printf: ignore '0' flag if '-' is also used.

This is what the standards require. Previously, the '0' flag would effectively override '-'.

Here is a program that demonstrates the problem:

#include <stdio.h>
int main(void) {
        printf("|%-020d|\n", 123);
        printf("|%0-20d|\n", 123);
        printf("|%0*d|\n", -20, 123);
}
This commit is contained in:
Stephen Heumann 2023-04-16 15:39:49 -05:00
parent bdfed3628d
commit b7b4182cd2
1 changed files with 7 additions and 1 deletions

View File

@ -4942,11 +4942,15 @@ Flag lda [format] get the character
bne fl1
lda #1 left justify the output
sta ~leftJustify
lda #' ' pad with spaces (ignore any '0' flag)
sta ~paddChar
bra fl5
fl1 cmp #'0' if it is a '0' then
bne fl2
sta ~paddChar padd with '0' characters
ldx ~leftJustify if not left justifying then
bne fl5
sta ~paddChar padd with '0' characters
bra fl5
fl2 cmp #'+' if it is a '+' or ' ' then
@ -4988,6 +4992,8 @@ GetSize stz val assume a value of 0
inc a positive with - flag
ldx #1
stx ~leftJustify
ldx #' '
stx ~paddChar
bra fv1
fv0 lda #0 negative precision is ignored
stz ~precisionSpecified