Manually constructed ByteArray toString segfaults
System information
Ubuntu 18.10
Gjs 239f338e
Bug information
Up to 1.52, could create a ByteArray and fill it with bytes in a loop. Now it segfaults unless I explicitly use the Uint8Array constructor or call .toString() method instead of byteArray.toString() export. Calling the method works but segfaults too when length is 0, while the older version used to return an empty string.
Steps to reproduce
const { ByteArray, toString } = imports.byteArray;
const bytes = new ByteArray(1); // Uint8Array ok, ByteArray crashes.
print(bytes.length);
bytes[0] = 112;
print(toString(bytes));
Current behaviour
1
Thread 1 "gjs" received signal SIGSEGV, Segmentation fault.
0x00007ffff7c039f4 in to_string_impl (context=0x5555555852b0, byte_array=...,
encoding=<optimized out>, rval=...)
at .../jhbuild/checkout/gjs/gjs/byteArray.cpp:77
77 if (data[len - 1] == 0 || memchr(data, 0, len))```
Expected behaviour
1
p