libmm-glib,common-helpers: make hexstr2bin() return a GError

This util method checks whether the input string is a valid hex
string, so make sure we return a GError on failure.
This commit is contained in:
Aleksander Morgado
2021-02-23 11:35:11 +00:00
parent dbdf67e9f7
commit 657cabcfce
11 changed files with 90 additions and 153 deletions
+9 -10
View File
@@ -2330,21 +2330,20 @@ decode (MMIfaceModem3gppUssd *self,
const gchar *reply,
GError **error)
{
gchar *bin, *utf8;
guint8 *unpacked;
gsize bin_len;
guint32 unpacked_len;
g_autofree gchar *bin = NULL;
g_autofree guint8 *unpacked = NULL;
gsize bin_len = 0;
guint32 unpacked_len;
bin = mm_utils_hexstr2bin (reply, &bin_len, error);
if (!bin)
return NULL;
bin = mm_utils_hexstr2bin (reply, &bin_len);
unpacked = mm_charset_gsm_unpack ((guint8*) bin, (bin_len * 8) / 7, 0, &unpacked_len);
/* if the last character in a 7-byte block is padding, then drop it */
if ((bin_len % 7 == 0) && (unpacked[unpacked_len - 1] == 0x0d))
unpacked_len--;
utf8 = (char*) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len);
g_free (bin);
g_free (unpacked);
return utf8;
return (gchar*) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len);
}
/*****************************************************************************/
+1 -1
View File
@@ -188,7 +188,7 @@ match_info_to_ip4_addr (GMatchInfo *match_info,
else
g_assert_not_reached ();
bin = mm_utils_hexstr2bin (buf, &bin_len);
bin = mm_utils_hexstr2bin (buf, &bin_len, NULL);
if (!bin || bin_len != 4)
goto done;