summaryrefslogtreecommitdiff
path: root/gconf/gconf-value.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@pobox.com>1999-10-05 23:17:15 +0000
committerHavoc Pennington <hp@src.gnome.org>1999-10-05 23:17:15 +0000
commite590ef5e8718d57979d71eb4c7078a2fb3ec16f3 (patch)
treedf15211f7841a85c2e6813193cd88d18b1c28aa4 /gconf/gconf-value.c
parent6b8a03886ee6fc2480893b04a8309b7d35b1186b (diff)
downloadgconf-e590ef5e8718d57979d71eb4c7078a2fb3ec16f3.tar.gz
Add checks for empty lists, and all the various list types.
1999-10-05 Havoc Pennington <hp@pobox.com> * tests/testgconf.c (check_list_storage): Add checks for empty lists, and all the various list types. * gconf/gconf-value.c (g_conf_value_to_string): Fix a segfault (not always allocating a large enough buffer)
Diffstat (limited to 'gconf/gconf-value.c')
-rw-r--r--gconf/gconf-value.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/gconf/gconf-value.c b/gconf/gconf-value.c
index 85b2db45..d761256d 100644
--- a/gconf/gconf-value.c
+++ b/gconf/gconf-value.c
@@ -238,17 +238,19 @@ g_conf_value_to_string(GConfValue* value)
retval = g_strdup("[]");
else
{
- gchar* buf;
- guint bufsize = 128;
+ gchar* buf = NULL;
+ guint bufsize = 64;
guint cur = 0;
g_assert(list != NULL);
- buf = g_malloc(bufsize);
+ buf = g_malloc(bufsize+3); /* my +3 superstition */
buf[0] = '[';
++cur;
+ g_assert(cur < bufsize);
+
while (list != NULL)
{
gchar* elem;
@@ -260,24 +262,31 @@ g_conf_value_to_string(GConfValue* value)
len = strlen(elem);
- if ((cur + len) >= bufsize)
+ if ((cur + len + 2) >= bufsize) /* +2 for '\0' and comma */
{
- bufsize *= 2;
- buf = g_realloc(buf, bufsize);
- buf[bufsize-1] = '\0'; /* paranoia */
+ bufsize = MAX(bufsize*2, bufsize+len+4);
+ buf = g_realloc(buf, bufsize+3);
}
+
+ g_assert(cur < bufsize);
strcpy(&buf[cur], elem);
cur += len;
+ g_assert(cur < bufsize);
+
g_free(elem);
buf[cur] = ',';
++cur;
+
+ g_assert(cur < bufsize);
list = g_slist_next(list);
}
+ g_assert(cur < bufsize);
+
buf[cur-1] = ']'; /* overwrites last comma */
buf[cur] = '\0';