From d5760968584ce3781ff25d13030e0a5fe3d5dba4 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sun, 2 Dec 2007 22:17:27 +0100 Subject: [PATCH] use GString to convert a strlist propery to string instead of a static buffer Instead of a static 256 chars buffer use a GString when converting strlist properties to string. This prevents clipping the list. Also fixes a hal crash because the old code didn't do a proper \0 terminate when the string overflowed (strncpy is a very nice function *cough*). Eventually the string containing garbage would be passed over dbus to the runner which would disconnect from the private bus. --- hald/device.c | 25 ++++++++----------------- 1 files changed, 8 insertions(+), 17 deletions(-) diff --git a/hald/device.c b/hald/device.c index 9514c9d..a3b84f4 100644 --- a/hald/device.c +++ b/hald/device.c @@ -160,28 +160,19 @@ hal_property_to_string (HalProperty *prop) case HAL_PROPERTY_TYPE_STRLIST: { GSList *iter; - guint i; - char buf[256]; + GString *buf; + + buf = g_string_new (""); - i = 0; - buf[0] = '\0'; - for (iter = hal_property_get_strlist (prop); - iter != NULL && i < sizeof(buf); + for (iter = hal_property_get_strlist (prop); iter != NULL; iter = g_slist_next (iter)) { - guint len; - const char *str; - - str = (const char *) iter->data; - len = strlen (str); - strncpy (buf + i, str, sizeof(buf) - i); - i += len; + g_string_append (buf, (const char *) iter->data); - if (g_slist_next (iter) != NULL && i < sizeof(buf)) { - buf[i] = '\t'; - i++; + if (g_slist_next (iter) != NULL) { + g_string_append_c(buf, '\t'); } } - return g_strdup (buf); + return g_string_free (buf, FALSE); } default: -- 1.5.3.7