Code

fix off-by-one allocation error
authorJeff King <peff@peff.net>
Fri, 29 Jan 2010 10:31:30 +0000 (05:31 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 29 Jan 2010 17:56:12 +0000 (09:56 -0800)
Caught by valgrind in t5516. Reading the code shows we
malloc enough for our string, but not trailing NUL.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-push.c

index 5df66081a6ff0ca5087ff9a2ac4042d8ec651499..5633f0ade49f7c845665b7aab202be18a8cc9d8d 100644 (file)
@@ -52,7 +52,7 @@ static void set_refspecs(const char **refs, int nr)
                } else if (deleterefs && !strchr(ref, ':')) {
                        char *delref;
                        int len = strlen(ref)+1;
-                       delref = xmalloc(len);
+                       delref = xmalloc(len+1);
                        strcpy(delref, ":");
                        strcat(delref, ref);
                        ref = delref;