From b2724c87872aaec55dd7e5529aa029c3108b43a5 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 19 Jun 2014 17:26:56 -0400 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/name-rev.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'builtin/name-rev.c') diff --git a/builtin/name-rev.c b/builtin/name-rev.c index c824d4ec5..3c8f319be 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -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); -- cgit v1.2.1