Skip to content

Commit cddac45

Browse files
peffgitster
authored andcommitted
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 <[email protected]>
1 parent 3818b25 commit cddac45

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

branch.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,12 @@ void create_branch(const char *name, const char *start_name,
296296
if (!dont_change_ref) {
297297
struct ref_transaction *transaction;
298298
struct strbuf err = STRBUF_INIT;
299-
char msg[PATH_MAX + 20];
299+
char *msg;
300300

301301
if (forcing)
302-
snprintf(msg, sizeof msg, "branch: Reset to %s",
303-
start_name);
302+
msg = xstrfmt("branch: Reset to %s", start_name);
304303
else
305-
snprintf(msg, sizeof msg, "branch: Created from %s",
306-
start_name);
304+
msg = xstrfmt("branch: Created from %s", start_name);
307305

308306
transaction = ref_transaction_begin(&err);
309307
if (!transaction ||
@@ -314,6 +312,7 @@ void create_branch(const char *name, const char *start_name,
314312
die("%s", err.buf);
315313
ref_transaction_free(transaction);
316314
strbuf_release(&err);
315+
free(msg);
317316
}
318317

319318
if (real_ref && track)

0 commit comments

Comments
 (0)