Skip to content

Commit

Permalink
Check overflow in printf() (#260)
Browse files Browse the repository at this point in the history
vtereshkov committed Dec 23, 2022
1 parent b01b677 commit 48bda72
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion playground/umka.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/umka_vm.c
Original file line number Diff line number Diff line change
@@ -1322,6 +1322,19 @@ static FORCE_INLINE void doBuiltinPrintf(Fiber *fiber, HeapPages *pages, bool co
!(typeKindReal(typeKind) && typeKindReal(expectedTypeKind)))
error->runtimeHandler(error->context, "Incompatible types %s and %s in printf()", typeKindSpelling(expectedTypeKind), typeKindSpelling(typeKind));

// Check overflow
if (expectedTypeKind != TYPE_VOID)
{
Const arg;
if (typeKindReal(expectedTypeKind))
arg.realVal = fiber->top->realVal;
else
arg.intVal = fiber->top->intVal;

if (typeOverflow(expectedTypeKind, arg))
error->runtimeHandler(error->context, "Overflow of %s", typeKindSpelling(expectedTypeKind));
}

char curFormatBuf[DEFAULT_STR_LEN + 1];
char *curFormat = curFormatBuf;
if (formatLen + 1 > sizeof(curFormatBuf))

0 comments on commit 48bda72

Please sign in to comment.