[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`.
This commit is contained in:
Thomas Marshall 2024-03-03 10:43:35 +00:00 committed by GitHub
parent 93556d4620
commit 7e4b1f8e19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 4 deletions

View file

@ -12122,7 +12122,7 @@ rb_interned_str_cstr(const char *ptr)
VALUE
rb_enc_interned_str(const char *ptr, long len, rb_encoding *enc)
{
if (UNLIKELY(rb_enc_autoload_p(enc))) {
if (enc != NULL && UNLIKELY(rb_enc_autoload_p(enc))) {
rb_enc_autoload(enc);
}