From 6795fc4981d29e10da73a9eb23069d7f914115da Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Fri, 8 Nov 2024 20:58:53 +0000 Subject: [PATCH] rb_bug if rb_gc_impl_active_gc_name is too long This avoids the need to malloc, and reduces the complexity of truncating the long string for display in RUBY_DESCRIPTION. The developer of a GC implementation should be responsible for giving it a succinct name. --- gc.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/gc.c b/gc.c index 330c537578..08597e8b05 100644 --- a/gc.c +++ b/gc.c @@ -2780,13 +2780,8 @@ rb_gc_active_gc_name(void) { const char *gc_name = rb_gc_impl_active_gc_name(); if (strlen(gc_name) > RB_GC_MAX_NAME_LEN) { - char *truncated_gc_name = ruby_xmalloc(RB_GC_MAX_NAME_LEN + 1); - - rb_warn("GC module %s has a name larger than %d chars, it will be truncated\n", - gc_name, RB_GC_MAX_NAME_LEN); - - strncpy(truncated_gc_name, gc_name, RB_GC_MAX_NAME_LEN); - return (const char *)truncated_gc_name; + rb_bug("GC should have a name shorter than %d chars. Currently: %lu (%s)\n", + RB_GC_MAX_NAME_LEN, strlen(gc_name), gc_name); } return gc_name;