[libc] fix printf edge case with signed leading digits

Fixes specific case as in printf("%03d\n", -2), which
would put the sign digit after the leading zeros.

Make sure the sign bits are before any leading zeros or spaces.

Add test case for this.
This commit is contained in:
Travis Geiselbrecht
2013-07-31 11:16:01 -07:00
parent 9d9067f881
commit 2ae06216b1
2 changed files with 39 additions and 8 deletions

View File

@@ -76,6 +76,18 @@ void printf_tests(void)
printf("a%-9sa\n", "b");
printf("a%5sa\n", "thisisatest");
printf("%03d\n", -2); /* '-02' */
printf("%0+3d\n", -2); /* '-02' */
printf("%0+3d\n", 2); /* '+02' */
printf("%+3d\n", 2); /* ' +2' */
printf("% 3d\n", -2000); /* '-2000' */
printf("% 3d\n", 2000); /* ' 2000' */
printf("%+3d\n", 2000); /* '+2000' */
printf("%10s\n", "test"); /* ' test' */
printf("%010s\n", "test"); /* ' test' */
printf("%-10s\n", "test"); /* 'test ' */
printf("%-010s\n", "test"); /* 'test ' */
int err;
err = printf("a");