Re: [PATCH 15/67] convert trivial sprintf / strcpy calls to xsnprintf
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 16, 2015, 18:24 UTC
- Message-ID
- <xmqqh9muql2c.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20150916094814.GB13966@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 10 quoted lines
> On Tue, Sep 15, 2015 at 11:19:21PM -0400, Eric Sunshine wrote: > >> > strcpy(hexbuf[stage], sha1_to_hex(ce->sha1)); >> > - sprintf(ownbuf[stage], "%o", ce->ce_mode); >> > + xsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), "%o", ce->ce_mode); >> >> Interesting. I wonder if there are any (old/broken) compilers which >> would barf on this. If we care, perhaps sizeof(ownbuf[0]) instead? > > Good point. I've changed it to sizeof(ownbuf[0]).
Panda brain is lost here. What's the difference, other than that we will now appear to be measuring the size of the thing at index 0 while using that size to stuff data into a different location? All elements of the array are of the same size so there wouldn't be any difference either way, no?