Fix problem where strtol would accept invalid strings like "- +53".
This stemmed from its calling strtoul internally, causing it to accept extra while space and/or + signs. The fix is to have an alternate entry point for strtoul that skips that processing.
This commit is contained in:
parent
ee1b7e606d
commit
599c1e3c7b
16
stdlib.asm
16
stdlib.asm
|
@ -838,7 +838,7 @@ cn3 ph4 str save the starting string
|
||||||
ph2 base convert the unsigned number
|
ph2 base convert the unsigned number
|
||||||
ph4 ptr
|
ph4 ptr
|
||||||
ph4 str
|
ph4 str
|
||||||
jsl strtoul
|
jsl ~strtoul
|
||||||
stx val+2
|
stx val+2
|
||||||
sta val
|
sta val
|
||||||
txy see if we have an overflow
|
txy see if we have an overflow
|
||||||
|
@ -891,6 +891,8 @@ rt2 ldx val+2 get the value
|
||||||
****************************************************************
|
****************************************************************
|
||||||
*
|
*
|
||||||
* strtoul - convert a string to an unsigned long
|
* strtoul - convert a string to an unsigned long
|
||||||
|
* ~strtoul - alt entry point that does not parse leading
|
||||||
|
* white space and sign
|
||||||
*
|
*
|
||||||
* Inputs:
|
* Inputs:
|
||||||
* str - pointer to the string
|
* str - pointer to the string
|
||||||
|
@ -913,7 +915,13 @@ rtl equ 7 return address
|
||||||
val equ 3 value
|
val equ 3 value
|
||||||
foundOne equ 1 have we found a number?
|
foundOne equ 1 have we found a number?
|
||||||
|
|
||||||
pea 0 make room for & initialize foundOne
|
ldx #0
|
||||||
|
bra init
|
||||||
|
|
||||||
|
~strtoul entry alt entry point called from strtol
|
||||||
|
ldx #1
|
||||||
|
|
||||||
|
init pea 0 make room for & initialize foundOne
|
||||||
pea 0 make room for & initialize val
|
pea 0 make room for & initialize val
|
||||||
pea 0
|
pea 0
|
||||||
tsc set up direct page addressing
|
tsc set up direct page addressing
|
||||||
|
@ -924,13 +932,15 @@ foundOne equ 1 have we found a number?
|
||||||
;
|
;
|
||||||
lda ptr if ptr in non-null then
|
lda ptr if ptr in non-null then
|
||||||
ora ptr+2
|
ora ptr+2
|
||||||
beq sw1
|
beq sw0
|
||||||
lda str initialize it to str
|
lda str initialize it to str
|
||||||
sta [ptr]
|
sta [ptr]
|
||||||
ldy #2
|
ldy #2
|
||||||
lda str+2
|
lda str+2
|
||||||
sta [ptr],Y
|
sta [ptr],Y
|
||||||
|
|
||||||
|
sw0 txa just process number if called from strtol
|
||||||
|
bne db1a
|
||||||
sw1 lda [str] skip the white space
|
sw1 lda [str] skip the white space
|
||||||
and #$00FF
|
and #$00FF
|
||||||
tax
|
tax
|
||||||
|
|
Loading…
Reference in New Issue