1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-24 23:40:27 +00:00

Disallow nan and inf in jdn.

This commit is contained in:
Calvin Rose 2024-05-19 13:25:25 -05:00
parent ace60e1898
commit 03166a745a
2 changed files with 5 additions and 2 deletions

View File

@ -934,7 +934,7 @@ JanetFuncDef *janetc_pop_funcdef(JanetCompiler *c) {
int32_t slotchunks = (def->slotcount + 31) >> 5; int32_t slotchunks = (def->slotcount + 31) >> 5;
/* numchunks is min of slotchunks and scope->ua.count */ /* numchunks is min of slotchunks and scope->ua.count */
int32_t numchunks = slotchunks > scope->ua.count ? scope->ua.count : slotchunks; int32_t numchunks = slotchunks > scope->ua.count ? scope->ua.count : slotchunks;
uint32_t *chunks = janet_calloc(sizeof(uint32_t), slotchunks); uint32_t *chunks = janet_calloc(slotchunks, sizeof(uint32_t));
if (NULL == chunks) { if (NULL == chunks) {
JANET_OUT_OF_MEMORY; JANET_OUT_OF_MEMORY;
} }

View File

@ -379,7 +379,10 @@ static int print_jdn_one(struct pretty *S, Janet x, int depth) {
break; break;
case JANET_NUMBER: case JANET_NUMBER:
janet_buffer_ensure(S->buffer, S->buffer->count + BUFSIZE, 2); janet_buffer_ensure(S->buffer, S->buffer->count + BUFSIZE, 2);
int count = snprintf((char *) S->buffer->data + S->buffer->count, BUFSIZE, "%.17g", janet_unwrap_number(x)); double num = janet_unwrap_number(x);
if (isnan(num)) return 1;
if (isinf(num)) return 1;
int count = snprintf((char *) S->buffer->data + S->buffer->count, BUFSIZE, "%.17g", num);
S->buffer->count += count; S->buffer->count += count;
break; break;
case JANET_SYMBOL: case JANET_SYMBOL: