git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] branch -v: Prevent garbage output on remote refs
@ 2008-07-06  9:24 Brian Gernhardt
  2008-07-06 10:07 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Brian Gernhardt @ 2008-07-06  9:24 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

The stat string was only initialized if the ref was local, but was
always used in a printf.  This meant that whatever data was on the
stack got printed.  In the case of "branch -av", this was probably the
tracking information of the last local branch.  If the case of "branch
-rv", this was "@???" in my case.

Signed-off-by: Brian Gernhardt <benji@silverinsanity.com>
---

 After looking through the second get of changes I pulled, I tried this:

 $ git branch -av
 * master                 3195299 [ahead 1] Make rebase save ORIG_HEAD if changing current branch
   origin/HEAD            08b51f5 [ahead 1] Merge branch 'qq/maint'
   origin/gitk-for-paulus 7d8856d [ahead 1] gitk: Update German translation.

 Huh. That doesn't look right...  Let's try just showing the remotes:

 $ git branch -rv
   origin/HEAD            08b51f5 @???Merge branch 'qq/maint'
   origin/gitk-for-paulus 7d8856d @???gitk: Update German translation.

 That's definately not good.

 I guess that other people either have a compiler that is more careful about
 clearing stack variables, or don't use "branch -v".

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

diff --git a/builtin-branch.c b/builtin-branch.c
index e9423d1..470c59f 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -327,7 +327,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
 	if (verbose) {
 		struct strbuf subject;
 		const char *sub = " **** invalid ref ****";
-		char stat[128];
+		char stat[128] = "";
 
 		strbuf_init(&subject, 0);
 
-- 
1.5.6.2.336.g3195

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] branch -v: Prevent garbage output on remote refs
  2008-07-06  9:24 [PATCH] branch -v: Prevent garbage output on remote refs Brian Gernhardt
@ 2008-07-06 10:07 ` Junio C Hamano
  2008-07-06 16:13   ` Brian Gernhardt
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2008-07-06 10:07 UTC (permalink / raw)
  To: Brian Gernhardt; +Cc: Git List

Thanks, but I have pushed out a slightly different change.

-- >8 --
branch -r -v: do not spit out garbage

The codepath to emit relationship between the branch and what it tracks
forgot to initialize a string buffer stat[] to empty when showing a
tracking branch.  This moves the emptying so that the buffer starts as
empty and stays so when no information is added to fix this issue.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

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

diff --git a/builtin-branch.c b/builtin-branch.c
index e9423d1..ff71f3d 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -287,10 +287,8 @@ static void fill_tracking_info(char *stat, const char *branch_name)
 	int ours, theirs;
 	struct branch *branch = branch_get(branch_name);
 
-	if (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs)) {
-		stat[0] = '\0';
+	if (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs))
 		return;
-	}
 	if (!ours)
 		sprintf(stat, "[behind %d] ", theirs);
 	else if (!theirs)
@@ -330,6 +328,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
 		char stat[128];
 
 		strbuf_init(&subject, 0);
+		stat[0] = '\0';
 
 		commit = lookup_commit(item->sha1);
 		if (commit && !parse_commit(commit)) {

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] branch -v: Prevent garbage output on remote refs
  2008-07-06 10:07 ` Junio C Hamano
@ 2008-07-06 16:13   ` Brian Gernhardt
  0 siblings, 0 replies; 3+ messages in thread
From: Brian Gernhardt @ 2008-07-06 16:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List


On Jul 6, 2008, at 6:07 AM, Junio C Hamano wrote:

> Thanks, but I have pushed out a slightly different change.
>
> -- >8 --
> branch -r -v: do not spit out garbage

Looks good, and more importantly works.  Cherry-picked it from pu onto  
next.  Hopefully it'll move there on it's own soon.

~~ Brian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-07-06 16:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-06  9:24 [PATCH] branch -v: Prevent garbage output on remote refs Brian Gernhardt
2008-07-06 10:07 ` Junio C Hamano
2008-07-06 16:13   ` Brian Gernhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).