modem-helpers: ensure error is set when +CRM response parser doesn't match

This commit is contained in:
Aleksander Morgado
2013-04-24 23:05:12 +02:00
parent 1f99eaf80e
commit 40dc35a657

View File

@@ -2021,7 +2021,8 @@ mm_cdma_parse_crm_test_response (const gchar *reply,
{ {
gboolean result = FALSE; gboolean result = FALSE;
GRegex *r; GRegex *r;
GMatchInfo *match_info = NULL;
GError *match_error = NULL;
/* Expected reply format is: /* Expected reply format is:
* ---> AT+CRM=? * ---> AT+CRM=?
@@ -2031,46 +2032,52 @@ mm_cdma_parse_crm_test_response (const gchar *reply,
r = g_regex_new ("\\+CRM:\\s*\\((\\d+)-(\\d+)\\)", r = g_regex_new ("\\+CRM:\\s*\\((\\d+)-(\\d+)\\)",
G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW,
0, error); 0, error);
if (r) { g_assert (r != NULL);
GMatchInfo *match_info = NULL;
if (g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, error)) { if (g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, &match_error)) {
gchar *aux; gchar *aux;
guint min_val = 0; guint min_val = 0;
guint max_val = 0; guint max_val = 0;
aux = g_match_info_fetch (match_info, 1); aux = g_match_info_fetch (match_info, 1);
min_val = (guint) atoi (aux); min_val = (guint) atoi (aux);
g_free (aux); g_free (aux);
aux = g_match_info_fetch (match_info, 2); aux = g_match_info_fetch (match_info, 2);
max_val = (guint) atoi (aux); max_val = (guint) atoi (aux);
g_free (aux); g_free (aux);
if (min_val == 0 || if (min_val == 0 ||
max_val == 0 || max_val == 0 ||
min_val >= max_val) { min_val >= max_val) {
g_set_error (error, g_set_error (error,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Couldn't parse CRM range: " "Couldn't parse CRM range: "
"Unexpected range of RM protocols (%u,%u)", "Unexpected range of RM protocols (%u,%u)",
min_val, min_val,
max_val); max_val);
} else { } else {
*min = mm_cdma_get_rm_protocol_from_index (min_val, error); *min = mm_cdma_get_rm_protocol_from_index (min_val, error);
if (*min != MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN) { if (*min != MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN) {
*max = mm_cdma_get_rm_protocol_from_index (max_val, error); *max = mm_cdma_get_rm_protocol_from_index (max_val, error);
if (*max != MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN) if (*max != MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN)
result = TRUE; result = TRUE;
}
} }
} }
} else if (match_error) {
g_match_info_free (match_info); g_propagate_error (error, match_error);
g_regex_unref (r); } else {
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Couldn't parse CRM range: response didn't match (%s)",
reply);
} }
g_match_info_free (match_info);
g_regex_unref (r);
return result; return result;
} }