[PATCH] string-list.h: Add a value to string_list initializer lists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a NULL value in the end of STRING_LIST_INIT_NODUP and
STRING_LIST_DUP to initialize `compare_strings_fn`.

Signed-off-by: Tanay Abhra <tanayabh@xxxxxxxxx>
---
When I used a malloced string_list to play around with string-list API and
used the default init_list, it caused a seg fault. After an hour of debugging
I saw that comapre_strings_fn should be initialized to NULL. In C, even an
incomplete initialzer initializes every value to NULl or 0, so in normal
usage in the codebase this problem never occurs. Still it is better to be
thorough.

 string-list.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/string-list.h b/string-list.h
index de6769c..87ee419 100644
--- a/string-list.h
+++ b/string-list.h
@@ -15,8 +15,8 @@ struct string_list {
 	compare_strings_fn cmp; /* NULL uses strcmp() */
 };
 
-#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0 }
-#define STRING_LIST_INIT_DUP   { NULL, 0, 0, 1 }
+#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0, NULL }
+#define STRING_LIST_INIT_DUP   { NULL, 0, 0, 1, NULL }
 
 void print_string_list(const struct string_list *p, const char *text);
 void string_list_clear(struct string_list *list, int free_util);
-- 
1.9.0.GIT

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]