create_branch: move msg setup closer to point of use
In create_branch() we write the reflog msg into a buffer in the main function, but then use it only inside a conditional. If you carefully follow the logic, you can confirm that we never use the buffer uninitialized nor write when it would not be used. But we can make this a lot more obvious by simply moving the write step inside the conditional. Signed-off-by: Jeff King <peff@peff.net>
This commit is contained in:

committed by
Junio C Hamano

parent
6cd4a8982d
commit
3818b258dc
17
branch.c
17
branch.c
@ -234,7 +234,7 @@ void create_branch(const char *name, const char *start_name,
|
|||||||
{
|
{
|
||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
char *real_ref, msg[PATH_MAX + 20];
|
char *real_ref;
|
||||||
struct strbuf ref = STRBUF_INIT;
|
struct strbuf ref = STRBUF_INIT;
|
||||||
int forcing = 0;
|
int forcing = 0;
|
||||||
int dont_change_ref = 0;
|
int dont_change_ref = 0;
|
||||||
@ -290,19 +290,20 @@ void create_branch(const char *name, const char *start_name,
|
|||||||
die(_("Not a valid branch point: '%s'."), start_name);
|
die(_("Not a valid branch point: '%s'."), start_name);
|
||||||
hashcpy(sha1, commit->object.oid.hash);
|
hashcpy(sha1, commit->object.oid.hash);
|
||||||
|
|
||||||
if (forcing)
|
|
||||||
snprintf(msg, sizeof msg, "branch: Reset to %s",
|
|
||||||
start_name);
|
|
||||||
else if (!dont_change_ref)
|
|
||||||
snprintf(msg, sizeof msg, "branch: Created from %s",
|
|
||||||
start_name);
|
|
||||||
|
|
||||||
if (reflog)
|
if (reflog)
|
||||||
log_all_ref_updates = LOG_REFS_NORMAL;
|
log_all_ref_updates = LOG_REFS_NORMAL;
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
|
if (forcing)
|
||||||
|
snprintf(msg, sizeof msg, "branch: Reset to %s",
|
||||||
|
start_name);
|
||||||
|
else
|
||||||
|
snprintf(msg, sizeof msg, "branch: Created from %s",
|
||||||
|
start_name);
|
||||||
|
|
||||||
transaction = ref_transaction_begin(&err);
|
transaction = ref_transaction_begin(&err);
|
||||||
if (!transaction ||
|
if (!transaction ||
|
||||||
|
Reference in New Issue
Block a user