diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2017-04-19 10:42:20 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2017-04-19 10:42:24 +0200 |
commit | d09bc8baaa9fe93a72bb715530b1403a7a81c891 (patch) | |
tree | 1669d35a62b3a76f4e840542f793ed30dab8f33b | |
parent | 44daf791bbf0c251882f723e9fcc9c89606d69fc (diff) |
telit: use mm_get_uint_from_hex_str() to parse CSIM hex response
The regex is already limiting the string to 4 hex chars, so we can
definitely fit the number in a guint, no need a guint64.
-rw-r--r-- | plugins/telit/mm-modem-helpers-telit.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/plugins/telit/mm-modem-helpers-telit.c b/plugins/telit/mm-modem-helpers-telit.c index 1dd25424..8353c45d 100644 --- a/plugins/telit/mm-modem-helpers-telit.c +++ b/plugins/telit/mm-modem-helpers-telit.c @@ -125,7 +125,7 @@ mm_telit_parse_csim_response (const gchar *response, GRegex *r = NULL; gchar *str_code = NULL; gint retries = -1; - guint64 hex_code = 0x0; + guint hex_code; GError *inner_error = NULL; r = g_regex_new ("\\+CSIM:\\s*[0-9]+,\\s*\".*([0-9a-fA-F]{4})\"", G_REGEX_RAW, 0, NULL); @@ -144,9 +144,7 @@ mm_telit_parse_csim_response (const gchar *response, goto out; } - errno = 0; - hex_code = g_ascii_strtoull (str_code, NULL, 16); - if (hex_code == G_MAXUINT64 && errno == ERANGE) { + if (!mm_get_uint_from_hex_str (str_code, &hex_code)) { inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Could not recognize expected hex code in response '%s'", response); goto out; @@ -179,7 +177,7 @@ mm_telit_parse_csim_response (const gchar *response, if (hex_code < MM_TELIT_MIN_SIM_RETRY_HEX || hex_code > MM_TELIT_MAX_SIM_RETRY_HEX) { inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED, - "Unknown error returned '0x%04lx'", hex_code); + "Unknown error returned '0x%04x'", hex_code); goto out; } |