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.
This commit is contained in:
Aleksander Morgado
2017-04-19 10:42:20 +02:00
parent 44daf791bb
commit d09bc8baaa

View File

@@ -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;
}