From 6e9790667854b57f48631ab6203c0657d20c7ea0 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 13 Mar 2018 22:11:40 -0500 Subject: [PATCH] Make strtol/strtoul return LONG_MIN/LONG_MAX/ULONG_MAX for out-of-range values. This fixes #10. There are still issues with the end pointer value generated in error cases. --- stdlib.asm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/stdlib.asm b/stdlib.asm index a509ae8..7dfafbb 100644 --- a/stdlib.asm +++ b/stdlib.asm @@ -748,6 +748,14 @@ cn3 ph4 str save the starting string ; lda #ERANGE errno = ERANGE sta >errno + ldx #$7FFF return value = LONG_MAX + ldy #$FFFF + lda negative if negative then + beq ov1 + inx return value = LONG_MIN + iny +ov1 sty val + stx val+2 lda ptr if ptr <> NULL then ora ptr+2 bne rt1 @@ -920,7 +928,9 @@ cn5 lda foundOne if no digits were found, flag the error returnERANGE anop lda #ERANGE errno = ERANGE sta >errno - bra rt2 skip setting ptr + ldx #$FFFF return value = ULONG_MAX + txy + bra rt3 skip setting ptr ; ; return the results ; @@ -934,7 +944,7 @@ rt1 lda ptr if ptr is non-null then sta [ptr],Y rt2 ldx val+2 get the value ldy val - lda rtl fix the stack +rt3 lda rtl fix the stack sta base-1 lda rtl+1 sta base