From ccb45a8941f2b96a06c032a6d009b6b74c23b3a3 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 07:10:45 +0100 Subject: libmm-glib,helpers: ignore all leading whitespaces when parsing numbers --- libmm-glib/mm-common-helpers.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 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 8e0fc601..d2c54a1c 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1322,7 +1322,14 @@ mm_get_int_from_str (const gchar *str, glong num; guint eol = 0; - if (!str || !str[0]) + if (!str) + return FALSE; + + /* ignore all leading whitespaces */ + while (str[0] == ' ') + str++; + + if (!str[0]) return FALSE; for (num = 0; str[num]; num++) { @@ -1382,7 +1389,14 @@ mm_get_u64_from_str (const gchar *str, guint64 num; guint eol = 0; - if (!str || !str[0]) + if (!str) + return FALSE; + + /* ignore all leading whitespaces */ + while (str[0] == ' ') + str++; + + if (!str[0]) return FALSE; for (num = 0; str[num]; num++) { @@ -1434,6 +1448,10 @@ mm_get_u64_from_hex_str (const gchar *str, if (!str) return FALSE; + /* ignore all leading whitespaces */ + while (str[0] == ' ') + str++; + if (g_str_has_prefix (str, "0x")) str = &str[2]; -- cgit v1.2.3-70-g09d2