scanf: a sign and/or 0x prefix with no following digits should be a matching failure.

This applies to + or - signs for 'd' or 'i' conversions, and to '0x' or '0X' prefixes for 'i' and 'x' conversions. (The new support for signs on u/o/x conversions did not have the problem.)

These cases were treated as if they successfully matched a number, but now they are correctly treated as a failure, causing no assignment to be done and causing the function to return without processing any further directives.

(Incidentally, the handling of '0x' without following digits is something that differs in modern C libraries: macOS libc, glibc, and musl are all different. Our new behavior should match that of musl, which I believe is what is correct under the C standards.)
This commit is contained in:
Stephen Heumann 2021-02-07 21:57:24 -06:00
parent 3ef9687b7e
commit 539707344a

View File

@ -4787,7 +4787,6 @@ ef1 tax {...back to skipping whitespace}
bne sg2
inc minus
sg1 jsl ~getchar
inc read
sg2 ldx based if base 8, 16 are allowed then
beq lb2
cmp #'0' if the digit is '0' then
@ -4805,6 +4804,7 @@ lb1a jsl ~getchar
cmp #'x'
bne lb2
lb1b asl base use base 16
stz read '0x' alone should not match
dec ~scanWidth get the next character
jeq lb4a
bpl lb1c
@ -4903,7 +4903,7 @@ val ds 8 value
base dc i2'10' number base
based ds 2 based conversion?
minus ds 2 is the value negative?
read ds 2 # chars read
read ds 2 # of digits read
end
****************************************************************
@ -5228,7 +5228,8 @@ hx1 jsl ~getchar
beq hx1a
cmp #'X'
bne hx2
hx1a dec ~scanWidth accept the character
hx1a stz read ('0x' alone should not match)
dec ~scanWidth accept the character
jeq lb4a
bpl hx3
stz ~scanWidth
@ -5376,7 +5377,7 @@ val ds 8 value
base dc i2'10' number base
based ds 2 based conversion?
minus ds 2 is there a minus sign?
read ds 2 # chars read
read ds 2 # of digits read
end
****************************************************************