* [PATCH] Fix git-show-branch --current when not on a branch
@ 2008-05-23 23:00 Stephan Beyer
2008-05-26 12:09 ` Stephan Beyer
2008-05-26 22:05 ` Junio C Hamano
0 siblings, 2 replies; 4+ messages in thread
From: Stephan Beyer @ 2008-05-23 23:00 UTC (permalink / raw)
To: git
builtin-show-branch.c relied on resolve_ref() to return
"refs/heads/foo" if on branch foo. But if not on a branch,
it returns "HEAD". Hence, `head + pfxlen' (i.e. head+11)
is a memory address beyond the "HEAD" string, so that
further operation leads to access of uninitialized memory.
This commit fixes the bug by just not adding the
"refs/heads/"-length offset. So append_one_rev() operates
on "refs/heads/foo" instead of "foo", which still works.
But now it also operates correctly on "HEAD".
Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
---
builtin-show-branch.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 019abd3..412eba0 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -782,8 +782,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
has_head++;
}
if (!has_head) {
- int pfxlen = strlen("refs/heads/");
- append_one_rev(head + pfxlen);
+ append_one_rev(head);
}
}
--
1.5.5.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix git-show-branch --current when not on a branch
2008-05-23 23:00 [PATCH] Fix git-show-branch --current when not on a branch Stephan Beyer
@ 2008-05-26 12:09 ` Stephan Beyer
2008-05-26 22:05 ` Junio C Hamano
1 sibling, 0 replies; 4+ messages in thread
From: Stephan Beyer @ 2008-05-26 12:09 UTC (permalink / raw)
To: git
Nobody?
Description too bad? Patch not working? Spam-filtered?[1]
Regards,
Stephan
1. http://article.gmane.org/gmane.comp.version-control.git/82769
--
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix git-show-branch --current when not on a branch
2008-05-23 23:00 [PATCH] Fix git-show-branch --current when not on a branch Stephan Beyer
2008-05-26 12:09 ` Stephan Beyer
@ 2008-05-26 22:05 ` Junio C Hamano
2008-05-27 0:20 ` Stephan Beyer
1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2008-05-26 22:05 UTC (permalink / raw)
To: Stephan Beyer; +Cc: git
Stephan Beyer <s-beyer@gmx.net> writes:
> builtin-show-branch.c relied on resolve_ref() to return
> "refs/heads/foo" if on branch foo. But if not on a branch,
> it returns "HEAD". Hence, `head + pfxlen' (i.e. head+11)
> is a memory address beyond the "HEAD" string, so that
> further operation leads to access of uninitialized memory.
>
> This commit fixes the bug by just not adding the
> "refs/heads/"-length offset. So append_one_rev() operates
> on "refs/heads/foo" instead of "foo", which still works.
> But now it also operates correctly on "HEAD".
>
> Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
Thanks for a patch and (more importantly) prodding..
> builtin-show-branch.c | 3 +--
> 1 files changed, 1 insertions(+), 2 deletions(-)
>
> diff --git a/builtin-show-branch.c b/builtin-show-branch.c
> index 019abd3..412eba0 100644
> --- a/builtin-show-branch.c
> +++ b/builtin-show-branch.c
> @@ -782,8 +782,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
> has_head++;
> }
> if (!has_head) {
> - int pfxlen = strlen("refs/heads/");
> - append_one_rev(head + pfxlen);
> + append_one_rev(head);
This changes the output for normal case. How about doing it like this instead?
builtin-show-branch.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 019abd3..a383323 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -782,8 +782,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
has_head++;
}
if (!has_head) {
- int pfxlen = strlen("refs/heads/");
- append_one_rev(head + pfxlen);
+ int offset = !prefixcmp(head, "refs/heads/") ? 11 : 0;
+ append_one_rev(head + offset);
}
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix git-show-branch --current when not on a branch
2008-05-26 22:05 ` Junio C Hamano
@ 2008-05-27 0:20 ` Stephan Beyer
0 siblings, 0 replies; 4+ messages in thread
From: Stephan Beyer @ 2008-05-27 0:20 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1286 bytes --]
Hi,
> > builtin-show-branch.c | 3 +--
> > 1 files changed, 1 insertions(+), 2 deletions(-)
> >
> > diff --git a/builtin-show-branch.c b/builtin-show-branch.c
> > index 019abd3..412eba0 100644
> > --- a/builtin-show-branch.c
> > +++ b/builtin-show-branch.c
> > @@ -782,8 +782,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
> > has_head++;
> > }
> > if (!has_head) {
> > - int pfxlen = strlen("refs/heads/");
> > - append_one_rev(head + pfxlen);
> > + append_one_rev(head);
>
> This changes the output for normal case.
It does? How?
I cite my commit message:
> [...] So append_one_rev() operates
> on "refs/heads/foo" instead of "foo", which still works.
> But now it also operates correctly on "HEAD".
And I still think it's true.
I diff'ed the outputs of
git-show-branch --current
AND (just to go sure)
git-show-branch
on git.next
before and after the patch:
No difference.
> + int offset = !prefixcmp(head, "refs/heads/") ? 11 : 0;
Your version is the intuitive change and, of course, right,
but I don't see why we should do the prefixcmp() when it does
not change the resulting behavior in any way.
Regards,
Stephan
--
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-05-27 0:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-23 23:00 [PATCH] Fix git-show-branch --current when not on a branch Stephan Beyer
2008-05-26 12:09 ` Stephan Beyer
2008-05-26 22:05 ` Junio C Hamano
2008-05-27 0:20 ` Stephan Beyer
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).