aboutsummaryrefslogtreecommitdiff
path: root/libmm-glib/mm-common-helpers.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2020-12-21 13:52:54 +0100
committerAleksander Morgado <aleksander@aleksander.es>2021-02-23 11:35:11 +0000
commita211981d4a12b0ef6cab48b7a04ae9e5674cac01 (patch)
tree081c71748d5a369e632c1fa15ce6dd6d8c6ce493 /libmm-glib/mm-common-helpers.c
parent657cabcfce6794d2a2f629d63dbd56fc149dab2e (diff)
libmm-glib,common-helpers: make hexstr2bin() accept input string length
Optionally given explicitly, and -1 can be used to assume it's NUL-terminated.
Diffstat (limited to 'libmm-glib/mm-common-helpers.c')
-rw-r--r--libmm-glib/mm-common-helpers.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c
index b443f1ab..3a97e3be 100644
--- a/libmm-glib/mm-common-helpers.c
+++ b/libmm-glib/mm-common-helpers.c
@@ -1688,6 +1688,7 @@ mm_utils_hex2byte (const gchar *hex)
gchar *
mm_utils_hexstr2bin (const gchar *hex,
+ gssize len,
gsize *out_len,
GError **error)
{
@@ -1695,10 +1696,10 @@ mm_utils_hexstr2bin (const gchar *hex,
g_autofree gchar *buf = NULL;
gsize i;
gint a;
- gchar *opos;
- gsize len;
-
- len = strlen (hex);
+ gchar *opos
+;
+ if (len < 0)
+ len = strlen (hex);
/* Length must be a multiple of 2 */
if ((len % 2) != 0) {