diff options
author | Thomas Marshall <thomas@thomasmarshall.com> | 2024-03-03 10:43:35 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-03 10:43:35 +0000 |
commit | 7e4b1f8e1935a10df3c41ee60ca0987d73281126 (patch) | |
tree | 4a03894e654e309606cbdd8dfe3fa7241be6ab03 /ext/-test-/string/fstring.c | |
parent | 93556d46203545bc2364b1c0dd1281ba098f3cc9 (diff) |
[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`.
Diffstat (limited to 'ext/-test-/string/fstring.c')
-rw-r--r-- | ext/-test-/string/fstring.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/ext/-test-/string/fstring.c b/ext/-test-/string/fstring.c index d3062224d8..71c4b7f97e 100644 --- a/ext/-test-/string/fstring.c +++ b/ext/-test-/string/fstring.c @@ -19,13 +19,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 |