create_branch: use xstrfmt for reflog message

We generate a reflog message that contains some fixed text plus a branch name, and use a buffer of size PATH_MAX + 20. This mostly works if you assume that refnames are shorter than PATH_MAX, but: 1. That's not necessarily true. PATH_MAX is not always the filesystem's limit. 2. The "20" is not sufficiently large for the fixed text anyway. Let's just switch to a heap buffer so we don't have to even care. Signed-off-by: Jeff King <peff@peff.net>

Jeff King committed Mar 28, 2017 at 15:46 UTC cddac45219b70f121d30468811a9fbee78fa24f2
1 file changed +4 -5
branch.c
+4 -5
@@ -296,14 +296,12 @@ void create_branch(const char *name, const char *start_name,
296 if (!dont_change_ref) {
297 struct ref_transaction *transaction;
298 struct strbuf err = STRBUF_INIT;
299 - char msg[PATH_MAX + 20];
299 + char *msg;
300
301 if (forcing)
302 - snprintf(msg, sizeof msg, "branch: Reset to %s",
303 - start_name);
302 + msg = xstrfmt("branch: Reset to %s", start_name);
303 else
305 - snprintf(msg, sizeof msg, "branch: Created from %s",
306 - start_name);
304 + msg = xstrfmt("branch: Created from %s", start_name);
305
306 transaction = ref_transaction_begin(&err);
307 if (!transaction ||
@@ -314,6 +312,7 @@ void create_branch(const char *name, const char *start_name,
312 die("%s", err.buf);
313 ref_transaction_free(transaction);
314 strbuf_release(&err);
315 + free(msg);
316 }
317
318 if (real_ref && track)