mirror of
https://github.com/janet-lang/janet
synced 2025-04-27 21:23:17 +00:00
fix negative count passed to cfun_array_new_filled
This commit is contained in:
parent
65a9200cff
commit
7fda7709ff
@ -137,6 +137,7 @@ JANET_CORE_FN(cfun_array_new_filled,
|
|||||||
"Creates a new array of `count` elements, all set to `value`, which defaults to nil. Returns the new array.") {
|
"Creates a new array of `count` elements, all set to `value`, which defaults to nil. Returns the new array.") {
|
||||||
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) janet_panic("expected positive integer");
|
||||||
Janet x = (argc == 2) ? argv[1] : janet_wrap_nil();
|
Janet x = (argc == 2) ? argv[1] : janet_wrap_nil();
|
||||||
JanetArray *array = janet_array(count);
|
JanetArray *array = janet_array(count);
|
||||||
for (int32_t i = 0; i < count; i++) {
|
for (int32_t i = 0; i < count; i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user