diff options
author | Peter Wu <lekensteyn@gmail.com> | 2013-09-02 11:08:33 +0200 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2013-09-02 11:45:35 +0200 |
commit | 43cb53961b279af5ed961596737f053801da5fb8 (patch) | |
tree | dff8bb286f19c2a41d00294bf422c8e040203bf2 | |
parent | c3f1f2e85575c45128c054f128f0ec21bd3e377b (diff) | |
download | upower-43cb53961b279af5ed961596737f053801da5fb8.tar.gz |
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 <martin.pitt@ubuntu.com>
Signed-off-by: Peter Wu <lekensteyn@gmail.com>
-rw-r--r-- | src/linux/hidpp-device.c | 11 |
1 files 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; } |