diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c index a712d80f..a751fbdf 100644 --- a/src/stdio/vfprintf.c +++ b/src/stdio/vfprintf.c @@ -33,7 +33,7 @@ enum { BARE, LPRE, LLPRE, HPRE, HHPRE, BIGLPRE, - ZTPRE, JPRE, + ZTPRE, JPRE, PLAIN, WPRE, W1PRE, W3PRE, W6PRE, STOP, PTR, INT, UINT, ULLONG, LONG, ULONG, @@ -44,9 +44,10 @@ enum { MAXSTATE }; -#define S(x) [(x)-'A'] +#define ST_BASE '1' +#define S(x) [(x)-ST_BASE] -static const unsigned char states[]['z'-'A'+1] = { +static const unsigned char states[]['z'-ST_BASE+1] = { { /* 0: bare types */ S('d') = INT, S('i') = INT, S('o') = UINT, S('u') = UINT, S('x') = UINT, S('X') = UINT, @@ -94,10 +95,24 @@ static const unsigned char states[]['z'-'A'+1] = { S('o') = UMAX, S('u') = UMAX, S('x') = UMAX, S('X') = UMAX, S('n') = PTR, + }, { /* 8: explicit-width-prefixed bare equivalent */ + S('d') = INT, S('i') = INT, + S('o') = UINT, S('u') = UINT, + S('x') = UINT, S('X') = UINT, + S('n') = PTR, + }, { /* 9: w-prefixed */ + S('1') = W1PRE, S('3') = W3PRE, + S('6') = W6PRE, S('8') = HHPRE, + }, { /* 10: w1-prefixed */ + S('6') = HPRE, + }, { /* 11: w3-prefixed */ + S('2') = PLAIN, + }, { /* 12: w6-prefixed */ + S('4') = LLONG_MAX > LONG_MAX ? LLPRE : LPRE, } }; -#define OOB(x) ((unsigned)(x)-'A' > 'z'-'A') +#define OOB(x) ((unsigned)(x)-ST_BASE > 'z'-ST_BASE) union arg { @@ -547,6 +562,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, switch(t) { case 'n': switch(ps) { + case PLAIN: case BARE: *(int *)arg.p = cnt; break; case LPRE: *(long *)arg.p = cnt; break; case LLPRE: *(long long *)arg.p = cnt; break;