{"thread":{"id":"14309","subject":"[PATCH] branch -v: Prevent garbage output on remote refs","startedAt":"2008-07-06T09:24:39Z","lastAt":"2008-07-06T16:13:19Z","messageCount":3,"participants":["Brian Gernhardt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"82346","messageId":"1215336279-99480-1-git-send-email-benji@silverinsanity.com","threadId":"14309","inReplyTo":null,"subject":"[PATCH] branch -v: Prevent garbage output on remote refs","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2008-07-06T09:24:39Z","receivedAt":"2008-07-06T09:24:39Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"The stat string was only initialized if the ref was local, but was\nalways used in a printf.  This meant that whatever data was on the\nstack got printed.  In the case of \"branch -av\", this was probably the\ntracking information of the last local branch.  If the case of \"branch\n-rv\", this was \"@???\" in my case.\n\nSigned-off-by: Brian Gernhardt <benji@silverinsanity.com>\n---\n\n After looking through the second get of changes I pulled, I tried this:\n\n $ git branch -av\n * master                 3195299 [ahead 1] Make rebase save ORIG_HEAD if changing current branch\n   origin/HEAD            08b51f5 [ahead 1] Merge branch 'qq/maint'\n   origin/gitk-for-paulus 7d8856d [ahead 1] gitk: Update German translation.\n\n Huh. That doesn't look right...  Let's try just showing the remotes:\n\n $ git branch -rv\n   origin/HEAD            08b51f5 @???Merge branch 'qq/maint'\n   origin/gitk-for-paulus 7d8856d @???gitk: Update German translation.\n\n That's definately not good.\n\n I guess that other people either have a compiler that is more careful about\n clearing stack variables, or don't use \"branch -v\".\n\n builtin-branch.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex e9423d1..470c59f 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -327,7 +327,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,\n \tif (verbose) {\n \t\tstruct strbuf subject;\n \t\tconst char *sub = \" **** invalid ref ****\";\n-\t\tchar stat[128];\n+\t\tchar stat[128] = \"\";\n \n \t\tstrbuf_init(&subject, 0);\n \n-- \n1.5.6.2.336.g3195\n"},{"id":"82351","messageId":"7vhcb3fhqx.fsf@gitster.siamese.dyndns.org","threadId":"14309","inReplyTo":"1215336279-99480-1-git-send-email-benji@silverinsanity.com","subject":"Re: [PATCH] branch -v: Prevent garbage output on remote refs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-07-06T10:07:34Z","receivedAt":"2008-07-06T10:07:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks, but I have pushed out a slightly different change.\n\n-- >8 --\nbranch -r -v: do not spit out garbage\n\nThe codepath to emit relationship between the branch and what it tracks\nforgot to initialize a string buffer stat[] to empty when showing a\ntracking branch.  This moves the emptying so that the buffer starts as\nempty and stays so when no information is added to fix this issue.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n\n---\n builtin-branch.c |    5 ++---\n 1 files changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex e9423d1..ff71f3d 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -287,10 +287,8 @@ static void fill_tracking_info(char *stat, const char *branch_name)\n \tint ours, theirs;\n \tstruct branch *branch = branch_get(branch_name);\n \n-\tif (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs)) {\n-\t\tstat[0] = '\\0';\n+\tif (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs))\n \t\treturn;\n-\t}\n \tif (!ours)\n \t\tsprintf(stat, \"[behind %d] \", theirs);\n \telse if (!theirs)\n@@ -330,6 +328,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,\n \t\tchar stat[128];\n \n \t\tstrbuf_init(&subject, 0);\n+\t\tstat[0] = '\\0';\n \n \t\tcommit = lookup_commit(item->sha1);\n \t\tif (commit && !parse_commit(commit)) {\n"},{"id":"82374","messageId":"337634A4-0B60-4803-8EE9-6D0B377F5AEE@silverinsanity.com","threadId":"14309","inReplyTo":"7vhcb3fhqx.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] branch -v: Prevent garbage output on remote refs","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2008-07-06T16:13:19Z","receivedAt":"2008-07-06T16:13:19Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn Jul 6, 2008, at 6:07 AM, Junio C Hamano wrote:\n\n> Thanks, but I have pushed out a slightly different change.\n>\n> -- >8 --\n> branch -r -v: do not spit out garbage\n\nLooks good, and more importantly works.  Cherry-picked it from pu onto  \nnext.  Hopefully it'll move there on it's own soon.\n\n~~ Brian\n"}]}