git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] string_list_append: always set util pointer to NULL
@ 2011-02-12  5:18 Jeff King
  2011-02-12  7:43 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff King @ 2011-02-12  5:18 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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

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

* Re: [PATCH] string_list_append: always set util pointer to NULL
  2011-02-12  5:18 [PATCH] string_list_append: always set util pointer to NULL Jeff King
@ 2011-02-12  7:43 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2011-02-12  7:43 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Jeff King <peff@peff.net> writes:

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

Of course; the "Especially since" part is very convincing.

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

end of thread, other threads:[~2011-02-12  7:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-12  5:18 [PATCH] string_list_append: always set util pointer to NULL Jeff King
2011-02-12  7:43 ` 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).