Fix undefined behavior in String#append_as_bytes

The UNREACHABLE macro calls __builtin_unreachable, which according to
the [GCC docs](https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005funreachable):

> If control flow reaches the point of the __builtin_unreachable, the
> program is undefined.

But it can reach this point with the following script:

    "123".append_as_bytes("123")

This can crash on some platforms with a `Trace/BPT trap: 5`.
This commit is contained in:
Peter Zhu 2024-09-24 13:20:35 -04:00 committed by Jean Boussier
parent 4f0fe97995
commit c51d8ff458
Notes: git 2024-09-24 18:55:14 +00:00

View File

@ -3790,6 +3790,7 @@ rb_str_append_as_bytes(int argc, VALUE *argv, VALUE str)
if (ENC_CODERANGE(obj) != ENC_CODERANGE_7BIT) {
goto clear_cr;
}
break;
}
default:
UNREACHABLE;