replace trivial malloc + sprintf / strcpy calls with xstrfmt
It's a common pattern to do: foo = xmalloc(strlen(one) + strlen(two) + 1 + 1); sprintf(foo, "%s %s", one, two); (or possibly some variant with strcpy()s or a more complicated length computation). We can switch these to use xstrfmt, which is shorter, involves less error-prone manual computation, and removes many sprintf and strcpy calls which make it harder to audit the code for real buffer overflows. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
b7115a350b
commit
75faa45ae0
@ -1350,9 +1350,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
|
||||
* Then we need to make sure that we do not lose a locally
|
||||
* present file that is not ignored.
|
||||
*/
|
||||
pathbuf = xmalloc(namelen + 2);
|
||||
memcpy(pathbuf, ce->name, namelen);
|
||||
strcpy(pathbuf+namelen, "/");
|
||||
pathbuf = xstrfmt("%.*s/", namelen, ce->name);
|
||||
|
||||
memset(&d, 0, sizeof(d));
|
||||
if (o->dir)
|
||||
|
Reference in New Issue
Block a user