From: Junio C Hamano <gitster@pobox.com>
To: Stephan Beyer <s-beyer@gmx.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Fix git-show-branch --current when not on a branch
Date: Mon, 26 May 2008 15:05:40 -0700 [thread overview]
Message-ID: <7vhcck4t6z.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <alpine.DEB.1.10.0805240049400.3980@euler.pkqs.net> (Stephan Beyer's message of "Sat, 24 May 2008 01:00:38 +0200 (CEST)")
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);
}
}
next prev parent reply other threads:[~2008-05-26 22:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2008-05-27 0:20 ` Stephan Beyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vhcck4t6z.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=s-beyer@gmx.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).