# [PATCH] fix use of sometimes uninitialized variable 'msg'

11 messages from 2007-02-03 to 2007-02-03. Participants: Michael Coleman, Mike Coleman, Lars Hjemli, Junio C Hamano.
Thread: https://gitlist.dev/t/6641

## Michael Coleman, 2007-02-03 16:49

Subject: [PATCH] fix use of sometimes uninitialized variable 'msg'
Message-ID: <11705213633209-git-send-email-tutufan@gmail.com>
URL: https://gitlist.dev/e/11705213633209-git-send-email-tutufan%40gmail.com

```

```

## Michael Coleman, 2007-02-03 16:49

Subject: [PATCH] fix uninitialized use of msg buffer
Message-ID: <11705213662728-git-send-email-tutufan@gmail.com>
URL: https://gitlist.dev/e/11705213662728-git-send-email-tutufan%40gmail.com
In-Reply-To: <11705213633209-git-send-email-tutufan@gmail.com>

```
---
 builtin-branch.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/builtin-branch.c b/builtin-branch.c
index d60690b..ac64b99 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -315,7 +315,7 @@ static void create_branch(const char *name, const char *start_name,
 	struct ref_lock *lock;
 	struct commit *commit;
 	unsigned char sha1[20];
-	char ref[PATH_MAX], msg[PATH_MAX + 20];
+	char ref[PATH_MAX], msg[PATH_MAX + 20] = { 0 };
 
 	snprintf(ref, sizeof ref, "refs/heads/%s", name);
 	if (check_ref_format(ref))
-- 
1.5.0.rc3

```

## Mike Coleman, 2007-02-03 17:05

Subject: Re: [PATCH] fix use of sometimes uninitialized variable 'msg'
Message-ID: <loom.20070203T180123-680@post.gmane.org>
URL: https://gitlist.dev/e/loom.20070203T180123-680%40post.gmane.org
In-Reply-To: <11705213633209-git-send-email-tutufan@gmail.com>

```
Michael Coleman <tutufan <at> gmail.com> writes:
> 
> 
> 

Oops--I didn't realize a header email was going to be sent out, too.  Not quite
sure what happened there.  When I tested it before, I thought only one email got
sent.

Mike

```

## Lars Hjemli, 2007-02-03 18:17

Subject: [PATCH] builtin-branch: be prepared for ref-logging
Message-ID: <11705266492308-git-send-email-hjemli@gmail.com>
URL: https://gitlist.dev/e/11705266492308-git-send-email-hjemli%40gmail.com
In-Reply-To: <11705213662728-git-send-email-tutufan@gmail.com>

```
The test for reflog parameter to create_branch() should also have tested
for log_all_ref_updates. But there is no good reason not to prepare a
reflog message, so lets just do it.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---

If log_all_ref_updates==1 then the reflog will get an empty message with 
your patch. That is better than using an uninitialized message, but I think
it's still better to just prepare a proper message.


 builtin-branch.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/builtin-branch.c b/builtin-branch.c
index d60690b..16b589e 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -342,12 +342,7 @@ static void create_branch(const char *name, const char *start_name,
 	if (!lock)
 		die("Failed to lock ref for update: %s.", strerror(errno));
 
-	if (reflog) {
-		log_all_ref_updates = 1;
-		snprintf(msg, sizeof msg, "branch: Created from %s",
-			 start_name);
-	}
-
+	snprintf(msg, sizeof msg, "branch: Created from %s", start_name);
 	if (write_ref_sha1(lock, sha1, msg) < 0)
 		die("Failed to write ref: %s.", strerror(errno));
 }
-- 
1.5.0.rc2.ge4b0e

```

## Lars Hjemli, 2007-02-03 18:35

Subject: [PATCH] builtin-branch: be prepared for ref-logging
Message-ID: <11705277471962-git-send-email-hjemli@gmail.com>
URL: https://gitlist.dev/e/11705277471962-git-send-email-hjemli%40gmail.com
In-Reply-To: <11705213662728-git-send-email-tutufan@gmail.com>

```
The test for reflog parameter to create_branch() should also have tested
for log_all_ref_updates. But there is no good reason not to prepare a
reflog message, so lets just do it.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---

Sorry, the previous patch was obviously no good, since it didn't honour
the case where (reflog==1 && log_all_ref_updates==0)

This one should be better.


 builtin-branch.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/builtin-branch.c b/builtin-branch.c
index d60690b..a8c8c98 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -342,12 +342,10 @@ static void create_branch(const char *name, const char *start_name,
 	if (!lock)
 		die("Failed to lock ref for update: %s.", strerror(errno));
 
-	if (reflog) {
+	if (reflog)
 		log_all_ref_updates = 1;
-		snprintf(msg, sizeof msg, "branch: Created from %s",
-			 start_name);
-	}
 
+	snprintf(msg, sizeof msg, "branch: Created from %s", start_name);
 	if (write_ref_sha1(lock, sha1, msg) < 0)
 		die("Failed to write ref: %s.", strerror(errno));
 }
-- 
1.5.0.rc2.ge4b0e

```

## Junio C Hamano, 2007-02-03 18:55

Subject: Re: [PATCH] builtin-branch: be prepared for ref-logging
Message-ID: <7vzm7v5aw7.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vzm7v5aw7.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <11705266492308-git-send-email-hjemli@gmail.com>

```
Lars Hjemli <hjemli@gmail.com> writes:

> The test for reflog parameter to create_branch() should also have tested
> for log_all_ref_updates. But there is no good reason not to prepare a
> reflog message, so lets just do it.
>
> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
> ---
>
> If log_all_ref_updates==1 then the reflog will get an empty message with 
> your patch. That is better than using an uninitialized message, but I think
> it's still better to just prepare a proper message.

True, but don't you still need to set log_all_ref_updates while
you call write_ref_sha1() for that ref in order to make sure
that log_ref_write() sets O_CREAT in oflags?

```

## Junio C Hamano, 2007-02-03 19:50

Subject: Re: [PATCH] builtin-branch: be prepared for ref-logging
Message-ID: <7vr6t73tsi.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vr6t73tsi.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <11705277471962-git-send-email-hjemli@gmail.com>

```
Lars Hjemli <hjemli@gmail.com> writes:

> The test for reflog parameter to create_branch() should also have tested
> for log_all_ref_updates. But there is no good reason not to prepare a
> reflog message, so lets just do it.
>
> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
> ---
>
> Sorry, the previous patch was obviously no good, since it didn't honour
> the case where (reflog==1 && log_all_ref_updates==0)

Ah, I did not see your fix-up patch before I sent out my
comments.

Funny thing is that I thought I fixed this already, but
apparently I didn't.  It could have been one of my "fixing in
working tree, sending out a patch to the list for comments and
then forgetting to apply it".  Maybe not.

In any case, thanks for the fix.

```

## Lars Hjemli, 2007-02-03 20:38

Subject: Re: [PATCH] builtin-branch: be prepared for ref-logging
Message-ID: <8c5c35580702031238i612acda0p26aba8e3df747b1a@mail.gmail.com>
URL: https://gitlist.dev/e/8c5c35580702031238i612acda0p26aba8e3df747b1a%40mail.gmail.com
In-Reply-To: <7vr6t73tsi.fsf@assigned-by-dhcp.cox.net>

```
On 2/3/07, Junio C Hamano <junkio@cox.net> wrote:
> Funny thing is that I thought I fixed this already

Infact, you did:

  http://article.gmane.org/gmane.comp.version-control.git/37197

Don't know what happend to this one...

-- 
larsh

```

## Junio C Hamano, 2007-02-03 20:54

Subject: Re: [PATCH] builtin-branch: be prepared for ref-logging
Message-ID: <7v64aj3qtu.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v64aj3qtu.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <8c5c35580702031238i612acda0p26aba8e3df747b1a@mail.gmail.com>

```
"Lars Hjemli" <hjemli@gmail.com> writes:

> On 2/3/07, Junio C Hamano <junkio@cox.net> wrote:
>> Funny thing is that I thought I fixed this already
>
> Infact, you did:
>
>  http://article.gmane.org/gmane.comp.version-control.git/37197
>
> Don't know what happend to this one...

Thanks, and I do think that patch is better ;-).

```

## Lars Hjemli, 2007-02-03 21:20

Subject: Re: [PATCH] builtin-branch: be prepared for ref-logging
Message-ID: <8c5c35580702031320m2cdf2087k5e2de24d2ec0504@mail.gmail.com>
URL: https://gitlist.dev/e/8c5c35580702031320m2cdf2087k5e2de24d2ec0504%40mail.gmail.com
In-Reply-To: <7v64aj3qtu.fsf@assigned-by-dhcp.cox.net>

```
On 2/3/07, Junio C Hamano <junkio@cox.net> wrote:
> "Lars Hjemli" <hjemli@gmail.com> writes:
>
> > On 2/3/07, Junio C Hamano <junkio@cox.net> wrote:
> >> Funny thing is that I thought I fixed this already
> >
> > Infact, you did:
> >
> >  http://article.gmane.org/gmane.comp.version-control.git/37197
> >
> > Don't know what happend to this one...
>
> Thanks, and I do think that patch is better ;-).

Agreed

-- 
larsh

```

## Junio C Hamano, 2007-02-03 23:21

Subject: Re: [PATCH] builtin-branch: be prepared for ref-logging
Message-ID: <7v1wl63jzf.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v1wl63jzf.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <8c5c35580702031238i612acda0p26aba8e3df747b1a@mail.gmail.com>

```
"Lars Hjemli" <hjemli@gmail.com> writes:

> On 2/3/07, Junio C Hamano <junkio@cox.net> wrote:
>> Funny thing is that I thought I fixed this already
>
> Infact, you did:
>
>  http://article.gmane.org/gmane.comp.version-control.git/37197
>
> Don't know what happend to this one...

It turns out that I was missing another patch from the same day.

	http://article.gmane.org/gmane.comp.version-control.git/37238

I guess we need a patch secretary whose job is to keep track of
all the patches sent to the list and make sure nothing stays in
limbo X-<.

```
