From 43cb53961b279af5ed961596737f053801da5fb8 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 2 Sep 2013 11:08:33 +0200 Subject: hidpp: simplify setting model and serial I previously followed the model example for copying part of the string, but there is a much simpler way to build the name string using g_strdup_printf. Note that a simple strdup() is not sufficient for model since it does not have to be NUL terminated. Reported-by: Martin Pitt Signed-off-by: Peter Wu --- src/linux/hidpp-device.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/linux/hidpp-device.c b/src/linux/hidpp-device.c index f517b8d..c6d9fbe 100644 --- a/src/linux/hidpp-device.c +++ b/src/linux/hidpp-device.c @@ -650,7 +650,6 @@ hidpp_device_refresh (HidppDevice *device, { const HidppDeviceMap *map; gboolean ret = TRUE; - GString *name = NULL; HidppMessage msg = { }; guint len; HidppDevicePrivate *priv = device->priv; @@ -813,9 +812,7 @@ hidpp_device_refresh (HidppDevice *device, goto out; len = msg.l.params[1]; - name = g_string_new (""); - g_string_append_len (name, msg.l.params + 2, len); - priv->model = g_strdup (name->str); + priv->model = g_strdup_printf ("%.*s", len, msg.l.params + 2); } } @@ -837,10 +834,8 @@ hidpp_device_refresh (HidppDevice *device, if (!ret) goto out; - name = g_string_new (""); serialp = (guint32 *) &msg.l.params[1]; - g_string_printf (name, "%08X", g_ntohl(*serialp)); - priv->serial = g_strdup (name->str); + priv->serial = g_strdup_printf ("%08X", g_ntohl(*serialp)); } /* get battery status */ @@ -1011,8 +1006,6 @@ out: ret = TRUE; priv->is_present = FALSE; } - if (name != NULL) - g_string_free (name, TRUE); return ret; } -- cgit v1.2.1