1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-06 19:42:29 +00:00

Remove strnlen and correctly address #1600

This commit is contained in:
Calvin Rose
2025-09-01 14:04:30 -05:00
parent c90c737345
commit 148e108864

View File

@@ -1060,19 +1060,11 @@ void janet_buffer_format(
break;
}
case 's': {
JanetByteView bytes = janet_getbytes(argv, arg);
const uint8_t *s = bytes.bytes;
int32_t l = bytes.len;
const char *s = janet_getcbytes(argv, arg);
if (form[2] == '\0')
janet_buffer_push_bytes(b, s, l);
janet_buffer_push_cstring(b, s);
else {
if (l != (int32_t) strnlen((const char *) s, l))
janet_panic("string contains zeros");
if (!strchr(form, '.') && l >= 100) {
janet_panic("no precision and string is too long to be formatted");
} else {
nb = snprintf(item, MAX_ITEM, form, s);
}
nb = snprintf(item, MAX_ITEM, form, s);
}
break;
}