libc: support not printing 0 digit with precision of 0

This commit is contained in:
K. Lange 2020-04-30 20:25:08 +09:00
parent 7be561c1b1
commit cc8b933cda
2 changed files with 14 additions and 1 deletions

11
apps/test-printf.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdio.h>
int main(int argc, char * argv[]) {
printf("%.3d\n", 42);
printf("%.10d\n", 12345);
printf("%.1d\n", 0);
printf("%.0d\n", 0);
printf("%.0d\n", 1);
printf("%.0d\n", 123);
return 0;
}

View File

@ -7,7 +7,9 @@ static void print_dec(unsigned int value, unsigned int width, char * buf, int *
unsigned int i = 9;
if (precision == -1) precision = 1;
if (value < 10UL) {
if (value == 0) {
n_width = 0;
} else if (value < 10UL) {
n_width = 1;
} else if (value < 100UL) {
n_width = 2;