git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Björn Steinbrink <b.steinbrink@gmx.de>
Date
Jun 5, 2008, 23:31 UTC
Message-ID
<20080605233155.GA21698@atjola.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
Next: Junio C Hamano
Message 1 of 2 in “name-rev: Fix segmentation fault when using --all”
  1. name-rev: Fix segmentation fault when using --allBjörn Steinbrink, Jun 5, 2008
  2. Junio C HamanoJun 6, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.