Re: [PATCH] Check the format of more printf-type functions
On Sat, Nov 14, 2009 at 22:33, Tarmigan Casebolt <tarmigan+git@gmail.com> wrote:
Show 27 quoted lines
> We already have these checks in many printf-type functions that have
> prototypes which are in header files. Add these same checks to some
> more prototypes in header functions and to static functions in .c
> files.
>
> cc: Miklos Vajna <vmiklos@frugalware.org>
> Signed-off-by: Tarmigan Casebolt <tarmigan+git@gmail.com>
> ---
>
> Junio, please consider this for next. It will hopefully catch some bugs like
> the Content-Length one in http-backend.c.
>
> One extra warning is
> CC merge-recursive.o
> merge-recursive.c: In function ‘write_tree_from_memory’:
> merge-recursive.c:218: warning: field precision should have type ‘int’, but argument 5 has type ‘size_t’
>
> A fix that might work in practice (because pathnames won't be longer than
> an int?) is:
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -215,7 +215,9 @@ struct tree *write_tree_from_memory(struct merge_options *o)
> for (i = 0; i < active_nr; i++) {
> struct cache_entry *ce = active_cache[i];
> if (ce_stage(ce))
> - output(o, 0, "%d %.*s", ce_stage(ce), ce_namelen(ce), ce->name);
> + output(o, 0, "%d %.*s", ce_stage(ce), (int)ce_namelen(ce), ce->name);It'll do. The message is purely diagnostics.
> + if (ce_namelen(ce) > INT_MAX)
> + die("A filename was too long");That's overdoing it a little.