mirror of
https://github.com/byteworksinc/ORCALib.git
synced 2024-06-14 03:29:41 +00:00
printf: properly handle negative field width or precision arguments.
If the field width is given by an argument (when * is used in the format specification) and the value given is negative, it should be treated like a positive field width with the - flag. If a negative argument is given for the precision, it should be treated as if the precision was not specified. The following is an example of code that behaved incorrectly: #include <stdio.h> int main(void) { printf("%*iXX\n", -50, 123); }
This commit is contained in:
parent
71a25f0fef
commit
7c4141f03d
12
stdio.asm
12
stdio.asm
|
@ -4544,7 +4544,17 @@ GetSize stz val assume a value of 0
|
|||
bne gs1
|
||||
inc4 format skip the '*' char
|
||||
lda [argp] fetch the value
|
||||
sta val
|
||||
bpl fv1 do adjustments if negative:
|
||||
ldx ~precisionSpecified
|
||||
bne fv0
|
||||
eor #$ffff negative field width is like
|
||||
inc a positive with - flag
|
||||
ldx #1
|
||||
stx ~leftJustify
|
||||
bra fv1
|
||||
fv0 lda #0 negative precision is ignored
|
||||
stz ~precisionSpecified
|
||||
fv1 sta val
|
||||
inc argp remove it from the argument list
|
||||
inc argp
|
||||
gs0 lda val
|
||||
|
|
Loading…
Reference in New Issue
Block a user