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>
This commit is contained in:
parent
3818b258dc
commit
cddac45219
9
branch.c
9
branch.c
@ -296,14 +296,12 @@ void create_branch(const char *name, const char *start_name,
|
|||||||
if (!dont_change_ref) {
|
if (!dont_change_ref) {
|
||||||
struct ref_transaction *transaction;
|
struct ref_transaction *transaction;
|
||||||
struct strbuf err = STRBUF_INIT;
|
struct strbuf err = STRBUF_INIT;
|
||||||
char msg[PATH_MAX + 20];
|
char *msg;
|
||||||
|
|
||||||
if (forcing)
|
if (forcing)
|
||||||
snprintf(msg, sizeof msg, "branch: Reset to %s",
|
msg = xstrfmt("branch: Reset to %s", start_name);
|
||||||
start_name);
|
|
||||||
else
|
else
|
||||||
snprintf(msg, sizeof msg, "branch: Created from %s",
|
msg = xstrfmt("branch: Created from %s", start_name);
|
||||||
start_name);
|
|
||||||
|
|
||||||
transaction = ref_transaction_begin(&err);
|
transaction = ref_transaction_begin(&err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
@ -314,6 +312,7 @@ void create_branch(const char *name, const char *start_name,
|
|||||||
die("%s", err.buf);
|
die("%s", err.buf);
|
||||||
ref_transaction_free(transaction);
|
ref_transaction_free(transaction);
|
||||||
strbuf_release(&err);
|
strbuf_release(&err);
|
||||||
|
free(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (real_ref && track)
|
if (real_ref && track)
|
||||||
|
Loading…
Reference in New Issue
Block a user