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

[PATCH] list-objects: perform NULL check before the variable is dereferenced

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Apr 9, 2012, 10:45 UTC
Message-ID
<1333968311-29889-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 list-objects.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/list-objects.c b/list-objects.c
index 3dd4a96..34044d9 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -15,12 +15,13 @@ static void process_blob(struct rev_info *revs,
 			 const char *name,
 			 void *cb_data)
 {
-	struct object *obj = &blob->object;
+	struct object *obj;
 
 	if (!revs->blob_objects)
 		return;
-	if (!obj)
+	if (!blob)
 		die("bad blob object");
+	obj = &blob->object;
 	if (obj->flags & (UNINTERESTING | SEEN))
 		return;
 	obj->flags |= SEEN;
@@ -67,7 +68,7 @@ static void process_tree(struct rev_info *revs,
 			 const char *name,
 			 void *cb_data)
 {
-	struct object *obj = &tree->object;
+	struct object *obj;
 	struct tree_desc desc;
 	struct name_entry entry;
 	struct name_path me;
@@ -77,8 +78,9 @@ static void process_tree(struct rev_info *revs,
 
 	if (!revs->tree_objects)
 		return;
-	if (!obj)
+	if (!tree)
 		die("bad tree object");
+	obj = &tree->object;
 	if (obj->flags & (UNINTERESTING | SEEN))
 		return;
 	if (parse_tree(tree) < 0)
-- 
1.7.3.1.256.g2539c.dirty
Next: Junio C Hamano
Message 1 of 5 in “list-objects: perform NULL check before the variable is dereferenced”
  1. list-objects: perform NULL check before the variable is dereferencedNguyễn Thái Ngọc Duy, Apr 9, 2012
  2. Junio C HamanoApr 9, 2012
  3. Nguyen Thai Ngoc DuyApr 9, 2012
  4. Junio C HamanoApr 10, 2012
  5. Junio C HamanoApr 10, 2012

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.