git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] name-rev: Fix segmentation fault when using --all
@ 2008-06-05 23:31 Björn Steinbrink
  2008-06-06  4:06 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Björn Steinbrink @ 2008-06-05 23:31 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

In commit da2478db "describe --always: fall back to showing an
abbreviated object name" we lost the check that skips empty entries in
the object hash table when iterating over it in cmd_name_rev. That may
cause a NULL pointer being handed to show_name(), leading to a
segmentation fault. So add that check back again.

Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
---
I'm not totally sure if adding the check back to the loop is the correct
fix, or if I should have added it to show_name(), but as the empty
entries in the object hash table are a property of that table, I figured
that it's not show_name()'s business to handle that.

 builtin-name-rev.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index cde5de5..f153da0 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -280,9 +280,13 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
 		int i, max;
 
 		max = get_max_object_index();
-		for (i = 0; i < max; i++)
-			show_name(get_indexed_object(i), NULL,
+		for (i = 0; i < max; i++) {
+			struct object *obj = get_indexed_object(i);
+			if (!obj)
+				continue;
+			show_name(obj, NULL,
 				  always, allow_undefined, data.name_only);
+		}
 	} else {
 		int i;
 		for (i = 0; i < revs.nr; i++)
-- 
1.5.6.rc1.dirty

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] name-rev: Fix segmentation fault when using --all
  2008-06-05 23:31 [PATCH] name-rev: Fix segmentation fault when using --all Björn Steinbrink
@ 2008-06-06  4:06 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2008-06-06  4:06 UTC (permalink / raw)
  To: Björn Steinbrink; +Cc: git

Thanks.  Although I am unsure what "name-rev --all" is good for ;-), the
fix looks good.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-06-06  4:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-05 23:31 [PATCH] name-rev: Fix segmentation fault when using --all Björn Steinbrink
2008-06-06  4:06 ` Junio C Hamano

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).