string_list_append: always set util pointer to NULL
PATCH 1/1 string_list_append: always set util pointer to NULL
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.
---
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(-)
string-list.c +1 -0
@@ -153,6 +153,7 @@ struct string_list_item *string_list_append(struct string_list *list, const charALLOC_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++; }
Signature · 1 line
1.7.4
Quoted 11 lines · Jeff King
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.
Quoted 3 lines
Signed-off-by Jeff King <[email protected]>---
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.