threads / bug / 24873

objectname:short bug?

Subject: objectname:short bug?

## tl;dr

4 messages between Aug 26, 2010 and Aug 27, 2010.

replies: 3people: 3as markdown or json

Jay Soffian· Aug 26, 2010, 21:16 UTC · lore

$ ./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.
Jay Soffian· Aug 26, 2010, 21:34 UTC · re: Jay Soffian · lore

[PATCH] 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.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
 builtin/for-each-ref.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index a2b28c6..89e75c6 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -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));
 		}
 	}
 }
-- 
1.7.2.2.170.gb30b3d
Jeff King· Aug 26, 2010, 22:15 UTC · re: Jay Soffian · lore

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

On Thu, Aug 26, 2010 at 05:34:29PM -0400, Jay Soffian wrote:
> 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.

Show 9 quoted lines
> --- a/builtin/for-each-ref.c
> +++ b/builtin/for-each-ref.c
> @@ -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
Michael J Gruber· Aug 27, 2010, 07:08 UTC · re: Jay Soffian · lore

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

Jay Soffian venit, vidit, dixit 26.08.2010 23:34:
Show 24 quoted 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.
> 
> Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
> ---
>  builtin/for-each-ref.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
> index a2b28c6..89e75c6 100644
> --- a/builtin/for-each-ref.c
> +++ b/builtin/for-each-ref.c
> @@ -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

← back to recent threads