* cfg.mk (sc_prohibit-c99-printf-format): Add SC rule. * find/parser.c (parse_time): Change %ju to PRIuMAX. (insert_num): Likewise. * xargs/xargs.c (xargs_do_exec): Change %zu to PRIuMAX. --- cfg.mk | 12 ++++++++++++ find/parser.c | 6 +++--- xargs/xargs.c | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/cfg.mk b/cfg.mk index b251270e..dcabb6b7 100644 --- a/cfg.mk +++ b/cfg.mk @@ -102,6 +102,18 @@ sc_die_EXIT_FAILURE: exit 1; } \ || : +# Disallow the C99 printf size specifiers %z and %j as they're not portable. +# The gnulib printf replacement does support them, however the printf +# replacement is not currently explicitly depended on by the gnulib error() +# module for example. Also we use fprintf() in a few places to output simple +# formats but don't use the gnulib module as it is seen as overkill at present. +# We'd have to adjust the above gnulib items before disabling this. +sc_prohibit-c99-printf-format: + @cd $(srcdir) \ + && GIT_PAGER= git grep -n '%[0*]*[jz][udx]' -- "*/*.c" \ + && { echo '$(ME): Use PRI*MAX instead of %j or %z' 1>&2; exit 1; } \ + || : + # Exempt the contents of any usage function from the following. _continued_string_col_1 = \ s/^usage .*?\n}//ms;/\\\n\w/ and print ("$$ARGV\n"),$$e=1;END{$$e||=0;exit $$e} diff --git a/find/parser.c b/find/parser.c index 64d8931f..22b54a33 100644 --- a/find/parser.c +++ b/find/parser.c @@ -3254,13 +3254,13 @@ parse_time (const struct parser_table* entry, char *argv[], int *arg_ptr) (tval.kind == COMP_GT) ? " >" : ((tval.kind == COMP_LT) ? " <" : ((tval.kind == COMP_EQ) ? ">=" : " ?"))); t = our_pred->args.reftime.ts.tv_sec; - fprintf (stderr, "%ju %s", + fprintf (stderr, "%"PRIuMAX" %s", (uintmax_t) our_pred->args.reftime.ts.tv_sec, ctime (&t)); if (tval.kind == COMP_EQ) { t = our_pred->args.reftime.ts.tv_sec + DAYSECS; - fprintf (stderr, " < %ju %s", + fprintf (stderr, " < %"PRIuMAX" %s", (uintmax_t) t, ctime (&t)); } } @@ -3364,7 +3364,7 @@ insert_num (char **argv, int *arg_ptr, const struct parser_table *entry) ((c_type == COMP_LT) ? "lt" : ((c_type == COMP_EQ) ? "eq" : "?")), (c_type == COMP_GT) ? " >" : ((c_type == COMP_LT) ? " <" : ((c_type == COMP_EQ) ? " =" : " ?"))); - fprintf (stderr, "%ju\n", our_pred->args.numinfo.l_val); + fprintf (stderr, "%"PRIuMAX"\n", our_pred->args.numinfo.l_val); } return our_pred; } diff --git a/xargs/xargs.c b/xargs/xargs.c index 46307137..3bb660c6 100644 --- a/xargs/xargs.c +++ b/xargs/xargs.c @@ -1380,7 +1380,7 @@ xargs_do_exec (struct buildcmd_control *ctl, void *usercontext, int argc, char * default: { die (EXIT_FAILURE, errno, - _("read returned unexpected value %zu; " + _("read returned unexpected value %"PRIuMAX"; " "this is probably a bug, please report it"), r); } } /* switch on bytes read */ -- 2.19.2