From a211981d4a12b0ef6cab48b7a04ae9e5674cac01 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 21 Dec 2020 13:52:54 +0100 Subject: libmm-glib,common-helpers: make hexstr2bin() accept input string length Optionally given explicitly, and -1 can be used to assume it's NUL-terminated. --- libmm-glib/mm-common-helpers.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'libmm-glib/mm-common-helpers.c') 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) { -- cgit v1.2.3-70-g09d2