Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

Re: [VALGRIND PATCH for nth_last patch series] Fix invalid memory access

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:59

Thomas Rast [off-list ref] writes:
Actually the point of that exercise was to ignore branch (non)switches
of the form

  checkout: moving from A to A
Ahhh, Ok, that is what I missed.
I originally thought that this would be desirable behaviour, but now
that it causes so much trouble, I'm not that sure any more.  I still
think it would be more intuitive to not count them as switches (after
all git-checkout says 'Already on "$branch"'), but OTOH 'cd .; cd -'
also stays in the same directory.
An entry of the form "from A to A" is made only when you explicitly ask to
checkout the current branch by name (i.e. "git checkout" without any
parameter won't add such an entry to the reflog), so I tend to agree with
"cd" that the users may find it more natural if we counted them.

Having said all that, I think Dscho's one had an off-by-one (but it is
getting late and it may be I who has one).

When parsing "checkout: moving from master to side\n", match points at
"master to...", target points at "side\n", and len is 6 (length of
"master").  We want to see if target is "master\n" and ignore such an
entry, so we should be checking if target is one longer than len.

 sha1_name.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git c/sha1_name.c w/sha1_name.c
index 38c9f1b..9aed8ae 100644
--- c/sha1_name.c
+++ w/sha1_name.c
@@ -731,7 +731,10 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
 		return 0;
 
 	len = target - match - 4;
-	if (target[len] == '\n' && !strncmp(match, target, len))
+	if (len + 1 == strlen(target) &&
+	    target[len] == '\n' &&
+	    !memcmp(target, match, len))
+		/* switching same branch "from A to A\n" */
 		return 0;
 
 	nth = cb->cnt++ % cb->alloc;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help