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

[PATCH] string_list_append: always set util pointer to NULL

From
Jeff King <peff@peff.net>
Date
Feb 12, 2011, 05:18 UTC
Message-ID
<20110212051850.GA715@sigill.intra.peff.net>

It is not immediately obvious that the util field may contain random bytes after appending an item. Especially since the string_list_insert* functions _do_ explicitly zero the util pointer.

This does not appear to be a bug in any current git code, as all callers either fill in the util field immediately or never use it. However, it is worth it to be less surprising to new users of the string-list API who may expect it to be intialized to NULL.

Signed-off-by: Jeff King <peff@peff.net>
---
This bit me in some new code I was writing. I consider it a bug fix, but
even if you don't, I think it is still an API improvement. :)
 string-list.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/string-list.c b/string-list.c
index 9b023a2..5168118 100644
--- a/string-list.c
+++ b/string-list.c
@@ -153,6 +153,7 @@ struct string_list_item *string_list_append(struct string_list *list, const char
 	ALLOC_GROW(list->items, list->nr + 1, list->alloc);
 	list->items[list->nr].string =
 		list->strdup_strings ? xstrdup(string) : (char *)string;
+	list->items[list->nr].util = NULL;
 	return list->items + list->nr++;
 }
 
-- 
1.7.4
Next: Junio C Hamano
Message 1 of 2 in “string_list_append: always set util pointer to NULL”
  1. string_list_append: always set util pointer to NULLJeff King, Feb 12, 2011
  2. Junio C HamanoFeb 12, 2011

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.