From: Alex Riesen Date: Sun, 15 Nov 2009 14:17:26 GMT Subject: Re: [PATCH] Check the format of more printf-type functions Message-ID: <81b0412b0911150617x5ef81b1ao9236c49d549ef8ea@mail.gmail.com> In-Reply-To: <1258234393-5093-1-git-send-email-tarmigan+git@gmail.com> On Sat, Nov 14, 2009 at 22:33, Tarmigan Casebolt wrote: > 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 > Signed-off-by: Tarmigan Casebolt > --- > > 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.