summaryrefslogtreecommitdiff
path: root/src/mm-modem-helpers.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2020-05-19 11:28:56 +0200
committerAleksander Morgado <aleksander@aleksander.es>2020-05-19 13:44:23 +0200
commit3476e140ad0b97dee50d14530f0c3dc04a1651b0 (patch)
tree4355b6479bb43cf3feacf44ecdf6316c97f86e22 /src/mm-modem-helpers.c
parent8e033ba331647435bab95a071a450b9be977b295 (diff)
downloadModemManager-3476e140ad0b97dee50d14530f0c3dc04a1651b0.tar.gz
modem-helpers: use GPtrArray to build a GStrv
So that we avoid errors when building on ARM due to increasing target type alignment. mm-modem-helpers.c: In function 'mm_3gpp_parse_cnum_exec_response': mm-modem-helpers.c:3206:21: error: cast increases required alignment of target type [-Werror=cast-align] return (array ? (GStrv) g_array_free (array, FALSE) : NULL); ^
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r--src/mm-modem-helpers.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 869fd80ec..f319a9251 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -3172,9 +3172,9 @@ mm_3gpp_parse_clck_write_response (const gchar *reply,
GStrv
mm_3gpp_parse_cnum_exec_response (const gchar *reply)
{
- GArray *array = NULL;
- GRegex *r;
- GMatchInfo *match_info;
+ g_autoptr(GPtrArray) array = NULL;
+ g_autoptr(GRegex) r = NULL;
+ g_autoptr(GMatchInfo) match_info = NULL;
/* Empty strings also return NULL list */
if (!reply || !reply[0])
@@ -3184,26 +3184,22 @@ mm_3gpp_parse_cnum_exec_response (const gchar *reply)
G_REGEX_UNGREEDY, 0, NULL);
g_assert (r != NULL);
+ array = g_ptr_array_new ();
g_regex_match (r, reply, 0, &match_info);
while (g_match_info_matches (match_info)) {
- gchar *number;
+ g_autofree gchar *number = NULL;
number = g_match_info_fetch_named (match_info, "num");
-
- if (number && number[0]) {
- if (!array)
- array = g_array_new (TRUE, TRUE, sizeof (gchar *));
- g_array_append_val (array, number);
- } else
- g_free (number);
-
+ if (number && number[0])
+ g_ptr_array_add (array, g_steal_pointer (&number));
g_match_info_next (match_info, NULL);
}
- g_match_info_free (match_info);
- g_regex_unref (r);
+ if (!array->len)
+ return NULL;
- return (array ? (GStrv) g_array_free (array, FALSE) : NULL);
+ g_ptr_array_add (array, NULL);
+ return (GStrv) g_ptr_array_free (g_steal_pointer (&array), FALSE);
}
/*************************************************************************/