# [PATCH] name-rev: Fix segmentation fault when using --all

2 messages from 2008-06-05 to 2008-06-06. Participants: Björn Steinbrink, Junio C Hamano.
Thread: https://gitlist.dev/t/13819

## Björn Steinbrink, 2008-06-05 23:31

Subject: [PATCH] name-rev: Fix segmentation fault when using --all
Message-ID: <20080605233155.GA21698@atjola.homenet>
URL: https://gitlist.dev/e/20080605233155.GA21698%40atjola.homenet

```
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

```

## Junio C Hamano, 2008-06-06 04:06

Subject: Re: [PATCH] name-rev: Fix segmentation fault when using --all
Message-ID: <7v4p87xl4n.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v4p87xl4n.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20080605233155.GA21698@atjola.homenet>

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

```
