aboutsummaryrefslogtreecommitdiff
path: root/libmm-glib/mm-common-helpers.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2020-03-24 07:10:45 +0100
committerAleksander Morgado <aleksander@aleksander.es>2020-04-09 12:38:50 +0000
commitccb45a8941f2b96a06c032a6d009b6b74c23b3a3 (patch)
tree4888d64efdc425aeaf1c69b1b703867ca3961843 /libmm-glib/mm-common-helpers.c
parent7eee214b8e6e61db92d564b2757099620d4eccbf (diff)
libmm-glib,helpers: ignore all leading whitespaces when parsing numbers
Diffstat (limited to 'libmm-glib/mm-common-helpers.c')
-rw-r--r--libmm-glib/mm-common-helpers.c22
1 files changed, 20 insertions, 2 deletions
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];