stat: do not rely on undefined behavior in printf formats
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 6 Nov 2010 20:57:08 +0000 (13:57 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 7 Nov 2010 01:09:44 +0000 (18:09 -0700)
commitca9aa7596094c4af094edb7eb63648570d53c100
treedb5f45604c3bbdcf1b0cb2e68fdcd804a682bc2a
parent6c058b2dabe2e577d56e8c2c82cec550ff82f085
stat: do not rely on undefined behavior in printf formats

* src/stat.c (digits, printf_flags): New static vars.
(make_format): New function.
(out_string, out_int, out_uint, out_uint_o, out_uint_x):
(out_minus_zero): Use it to avoid undefined behavior when invoking
printf.
(print_it): Check for invalid conversion specifications such as
%..X and %1-X, which would otherwise rely on undefined behavior
when invoking printf.
* tests/misc/stat-nanoseconds: Check that the "I" printf flag
doesn't mess up in the C locale, as it formerly did on non-GNU
hosts.
src/stat.c
tests/misc/stat-nanoseconds