Magellan Linux

Contents of /trunk/hal/patches/hal-0.5.10-use-GString-to-convert-a-strlist-propery-to-string-i.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 597 - (show annotations) (download)
Mon May 19 19:05:19 2008 UTC (15 years, 11 months ago) by niro
File size: 1769 byte(s)
-gentoo patches

1 From d5760968584ce3781ff25d13030e0a5fe3d5dba4 Mon Sep 17 00:00:00 2001
2 From: Sjoerd Simons <sjoerd@luon.net>
3 Date: Sun, 2 Dec 2007 22:17:27 +0100
4 Subject: [PATCH] use GString to convert a strlist propery to string instead of a static buffer
5
6 Instead of a static 256 chars buffer use a GString when converting strlist
7 properties to string. This prevents clipping the list.
8
9 Also fixes a hal crash because the old code didn't do a proper \0 terminate
10 when the string overflowed (strncpy is a very nice function *cough*).
11 Eventually the string containing garbage would be passed over dbus to the
12 runner which would disconnect from the private bus.
13 ---
14 hald/device.c | 25 ++++++++-----------------
15 1 files changed, 8 insertions(+), 17 deletions(-)
16
17 diff --git a/hald/device.c b/hald/device.c
18 index 9514c9d..a3b84f4 100644
19 --- a/hald/device.c
20 +++ b/hald/device.c
21 @@ -160,28 +160,19 @@ hal_property_to_string (HalProperty *prop)
22 case HAL_PROPERTY_TYPE_STRLIST:
23 {
24 GSList *iter;
25 - guint i;
26 - char buf[256];
27 + GString *buf;
28 +
29 + buf = g_string_new ("");
30
31 - i = 0;
32 - buf[0] = '\0';
33 - for (iter = hal_property_get_strlist (prop);
34 - iter != NULL && i < sizeof(buf);
35 + for (iter = hal_property_get_strlist (prop); iter != NULL;
36 iter = g_slist_next (iter)) {
37 - guint len;
38 - const char *str;
39 -
40 - str = (const char *) iter->data;
41 - len = strlen (str);
42 - strncpy (buf + i, str, sizeof(buf) - i);
43 - i += len;
44 + g_string_append (buf, (const char *) iter->data);
45
46 - if (g_slist_next (iter) != NULL && i < sizeof(buf)) {
47 - buf[i] = '\t';
48 - i++;
49 + if (g_slist_next (iter) != NULL) {
50 + g_string_append_c(buf, '\t');
51 }
52 }
53 - return g_strdup (buf);
54 + return g_string_free (buf, FALSE);
55 }
56
57 default:
58 --
59 1.5.3.7
60