From b8baf3f3ee7727682cddafb6e7a589ac2a220a38 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 20 Sep 2024 22:20:43 +0200 Subject: [PATCH] [ruby/prism] check_string() should always return a valid C string * Otherwise it is invalid e.g. to call strlen() to the result, or to assume the argument was a string. * All callers are already checking for nil before. https://github.com/ruby/prism/commit/8197be883e --- prism/extension.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/prism/extension.c b/prism/extension.c index ea83f768fe..d8b35b7213 100644 --- a/prism/extension.c +++ b/prism/extension.c @@ -42,17 +42,11 @@ ID rb_id_source_for; /******************************************************************************/ /** - * Check if the given VALUE is a string. If it's nil, then return NULL. If it's - * not a string, then raise a type error. Otherwise return the VALUE as a C - * string. + * Check if the given VALUE is a string. If it's not a string, then raise a + * TypeError. Otherwise return the VALUE as a C string. */ static const char * check_string(VALUE value) { - // If the value is nil, then we don't need to do anything. - if (NIL_P(value)) { - return NULL; - } - // Check if the value is a string. If it's not, then raise a type error. if (!RB_TYPE_P(value, T_STRING)) { rb_raise(rb_eTypeError, "wrong argument type %" PRIsVALUE " (expected String)", rb_obj_class(value));