use xstrfmt to replace xmalloc + strcpy/strcat
It's easy to get manual allocation calculations wrong, and the use of strcpy/strcat raise red flags for people looking for buffer overflows (though in this case each site was fine). It's also shorter to use xstrfmt, and the printf-format tends to be easier for a reader to see what the final string will look like. 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
283101869b
commit
b2724c8787
@ -33,10 +33,7 @@ static void name_rev(struct commit *commit,
|
||||
return;
|
||||
|
||||
if (deref) {
|
||||
char *new_name = xmalloc(strlen(tip_name)+3);
|
||||
strcpy(new_name, tip_name);
|
||||
strcat(new_name, "^0");
|
||||
tip_name = new_name;
|
||||
tip_name = xstrfmt("%s^0", tip_name);
|
||||
|
||||
if (generation)
|
||||
die("generation: %d, but deref?", generation);
|
||||
|
Reference in New Issue
Block a user