Skip to contentSkip to conversation

objectname:short bug?

PATCH In review Jay Soffian 3 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw
$ ./git version
git version 1.7.1.88.g67687
$ ./git for-each-ref --format='%(objectname) %(refname:short)'
refs/tags | head -5
d5aef6e4d58cfe1549adef5b436f3ace984e8c86 gitgui-0.10.0
33682a5e98adfd8ba4ce0e21363c443bd273eb77 gitgui-0.10.1
ca9b793bda20c7d011c96895e9407fac2df9648b gitgui-0.10.2
8c178f72b54f387b84388d093a920ae45b8659dd gitgui-0.11.0
15c7170c8c1f6d4f8b8aa539987a92c45d06be9e gitgui-0.12.0
$ ./git for-each-ref --format='%(objectname:short) %(refname:short)'
refs/tags | head -5
8b1e557 gitgui-0.10.0
8b1e557 gitgui-0.10.1
8b1e557 gitgui-0.10.2
8b1e557 gitgui-0.11.0
8b1e557 gitgui-0.12.0

Just checked tip-of-master (b5442ca) and the issue still appears.

j.

#1 lore raw

PATCH 1/1 for-each-ref: fix objectname:short bug

When objectname:short was introduced, it forgot to copy the result of find_unique_abbrev. Because the result of find_unique_abbrev is a pointer to static buffer, this resulted in the same value being substituted in for each ref.

---
 builtin/for-each-ref.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
builtin/for-each-ref.c +2 -1
index a2b28c6..89e75c6 100644
@@ -228,7 +228,8 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
 			v->s = s;
 		}
 		else if (!strcmp(name, "objectname:short")) {
-			v->s = find_unique_abbrev(obj->sha1, DEFAULT_ABBREV);
+			v->s = xstrdup(find_unique_abbrev(obj->sha1,
+							  DEFAULT_ABBREV));
 		}
 	}
 }
Signature · 1 line
1.7.2.2.170.gb30b3d
#2 lore raw

Re: [PATCH] for-each-ref: fix objectname:short bug

Quoted 4 lines · Jay Soffian

When objectname:short was introduced, it forgot to copy the result of find_unique_abbrev. Because the result of find_unique_abbrev is a pointer to static buffer, this resulted in the same value being substituted in for each ref.

Yuck. I can't believe neither Michael nor I noticed this on first review.

builtin/for-each-ref.c static void grab_common_values(struct atom_value *val, int deref, struct object · line 232

Quoted 9 lines
builtin/for-each-ref.c +2 -1
@@ -228,7 +228,8 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
 			v->s = s;
 		}
 		else if (!strcmp(name, "objectname:short")) {
-			v->s = find_unique_abbrev(obj->sha1, DEFAULT_ABBREV);
+			v->s = xstrdup(find_unique_abbrev(obj->sha1,
+							  DEFAULT_ABBREV));

Your fix looks correct. It obviously leaks, but then so does 99% of the rest of for-each-ref.

-Peff

#3 lore raw

Re: [PATCH] for-each-ref: fix objectname:short bug

In reply to Jay Soffian

Jay Soffian venit, vidit, dixit 26.08.2010 23:34:

Quoted 15 lines

When objectname:short was introduced, it forgot to copy the result of find_unique_abbrev. Because the result of find_unique_abbrev is a pointer to static buffer, this resulted in the same value being substituted in for each ref.

---
 builtin/for-each-ref.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
builtin/for-each-ref.c +0 -0
index a2b28c6..89e75c6 100644

builtin/for-each-ref.c static void grab_common_values(struct atom_value *val, int deref, struct object · line 235

Quoted 9 lines
builtin/for-each-ref.c +2 -1
@@ -228,7 +228,8 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
 			v->s = s;
 		}
 		else if (!strcmp(name, "objectname:short")) {
-			v->s = find_unique_abbrev(obj->sha1, DEFAULT_ABBREV);
+			v->s = xstrdup(find_unique_abbrev(obj->sha1,
+							  DEFAULT_ABBREV));
 		}
 	}
 }

3 words:

embarrassing - sorry - thanks!

Michael