From 548c7cb9f517dcb8029bd9698187c81819e08edd Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Wed, 29 May 2024 11:07:07 -0700 Subject: merge revision(s) 7e4b1f8e1935a10df3c41ee60ca0987d73281126: [Backport #20322] [Bug #20322] Fix rb_enc_interned_str_cstr null encoding The documentation for `rb_enc_interned_str_cstr` notes that `enc` can be a null pointer, but this currently causes a segmentation fault when trying to autoload the encoding. This commit fixes the issue by checking for NULL before calling `rb_enc_autoload`. --- ext/-test-/string/fstring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext') diff --git a/ext/-test-/string/fstring.c b/ext/-test-/string/fstring.c index 7ee14a8570..8dfa36e345 100644 --- a/ext/-test-/string/fstring.c +++ b/ext/-test-/string/fstring.c @@ -21,13 +21,13 @@ bug_s_fstring_fake_str(VALUE self) VALUE bug_s_rb_enc_interned_str(VALUE self, VALUE encoding) { - return rb_enc_interned_str("foo", 3, RDATA(encoding)->data); + return rb_enc_interned_str("foo", 3, NIL_P(encoding) ? NULL : RDATA(encoding)->data); } VALUE bug_s_rb_enc_str_new(VALUE self, VALUE encoding) { - return rb_enc_str_new("foo", 3, RDATA(encoding)->data); + return rb_enc_str_new("foo", 3, NIL_P(encoding) ? NULL : RDATA(encoding)->data); } void -- cgit v1.2.3