mirror of
https://github.com/janet-lang/janet
synced 2025-02-09 13:30:00 +00:00
#951 - fix unchecked count in cfun_buffer_new_filled
This commit is contained in:
parent
a964b164a6
commit
d5a5c49357
@ -178,12 +178,13 @@ JANET_CORE_FN(cfun_buffer_new_filled,
|
|||||||
"Returns the new buffer.") {
|
"Returns the new buffer.") {
|
||||||
janet_arity(argc, 1, 2);
|
janet_arity(argc, 1, 2);
|
||||||
int32_t count = janet_getinteger(argv, 0);
|
int32_t count = janet_getinteger(argv, 0);
|
||||||
|
if (count < 0) count = 0;
|
||||||
int32_t byte = 0;
|
int32_t byte = 0;
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
byte = janet_getinteger(argv, 1) & 0xFF;
|
byte = janet_getinteger(argv, 1) & 0xFF;
|
||||||
}
|
}
|
||||||
JanetBuffer *buffer = janet_buffer(count);
|
JanetBuffer *buffer = janet_buffer(count);
|
||||||
if (buffer->data)
|
if (buffer->data && count > 0)
|
||||||
memset(buffer->data, byte, count);
|
memset(buffer->data, byte, count);
|
||||||
buffer->count = count;
|
buffer->count = count;
|
||||||
return janet_wrap_buffer(buffer);
|
return janet_wrap_buffer(buffer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user