From d15ed616e91b1d0c24aa6ee2405c9d8607cc8d1c Mon Sep 17 00:00:00 2001 From: Kwarde Date: Tue, 22 Jul 2025 06:45:46 +0200 Subject: [PATCH] atoi: Prevent (unsigned) overflow --- src/convert.asm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/convert.asm b/src/convert.asm index 5f10c7d..1b5b7da 100644 --- a/src/convert.asm +++ b/src/convert.asm @@ -150,6 +150,12 @@ atoi: .calcNum_cnt: imul r9 + mov rdx, -1 + sub rdx, r10 + cmp rax, rdx + ;TODO: Add signed checks + ja .overflow + add r10, rax dec rdi inc r8 @@ -159,6 +165,10 @@ atoi: .wrapup_neg: neg r10 + jmp .quit + + .overflow: + xor r10, r10 .quit: mov rax, r10