From 03166a745a0957bb90336648938efb56dc557357 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 19 May 2024 13:25:25 -0500 Subject: [PATCH] Disallow nan and inf in jdn. --- src/core/compile.c | 2 +- src/core/pp.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/compile.c b/src/core/compile.c index 4f45ff1f..93ae2039 100644 --- a/src/core/compile.c +++ b/src/core/compile.c @@ -934,7 +934,7 @@ JanetFuncDef *janetc_pop_funcdef(JanetCompiler *c) { int32_t slotchunks = (def->slotcount + 31) >> 5; /* numchunks is min of slotchunks and scope->ua.count */ 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) { JANET_OUT_OF_MEMORY; } diff --git a/src/core/pp.c b/src/core/pp.c index bba70b6b..4b44c354 100644 --- a/src/core/pp.c +++ b/src/core/pp.c @@ -379,7 +379,10 @@ static int print_jdn_one(struct pretty *S, Janet x, int depth) { break; case JANET_NUMBER: 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; break; case JANET_SYMBOL: