shared: enforce compatible C-type argument for nm_utils_strv_dup()

Use a macro that uses NM_CAST_STRV_CC() to cast the strv argument. Note that
NM_CAST_STRV_CC() uses C11's _Generic() to check whether the argument is
of a valid type.
This commit is contained in:
Thomas Haller 2020-08-24 19:07:16 +02:00
parent 94b4276058
commit c25f4d947a
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
7 changed files with 17 additions and 16 deletions

View file

@ -1277,7 +1277,7 @@ call_cmd (NmCli *nmc, GTask *task, const NMCCommand *cmd, int argc, const char *
*call = (CmdCall) {
.cmd = cmd,
.argc = argc,
.argv = nm_utils_strv_dup ((char **) argv, argc, TRUE),
.argv = nm_utils_strv_dup (argv, argc, TRUE),
.task = task,
};
nmc_client_new_async (NULL,

View file

@ -8913,7 +8913,7 @@ do_connection_load (const NMCCommand *cmd, NmCli *nmc, int argc, const char *con
return;
}
filenames = (const char **) nm_utils_strv_dup ((char **) argv, argc, FALSE);
filenames = (const char **) nm_utils_strv_dup (argv, argc, FALSE);
nm_client_load_connections (nmc->client, (char **) filenames, &failures, NULL, &error);
if (error) {

View file

@ -2378,7 +2378,7 @@ do_device_modify (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const
*info = (ModifyInfo) {
.nmc = nmc,
.argc = argc,
.argv = nm_utils_strv_dup ((char **) argv, argc, TRUE),
.argv = nm_utils_strv_dup (argv, argc, TRUE),
};
nm_device_get_applied_connection_async (device, 0, NULL, modify_get_applied_cb, info);

View file

@ -1106,7 +1106,7 @@ get_property (GObject *object, guint prop_id,
case PROP_SEEN_BSSIDS:
g_value_take_boxed (value,
priv->seen_bssids
? nm_utils_strv_dup (priv->seen_bssids->pdata,
? nm_utils_strv_dup ((char **) priv->seen_bssids->pdata,
priv->seen_bssids->len,
TRUE)
: NULL);

View file

@ -189,7 +189,7 @@ next:
}
if ( arr
&& arr->len > 0)
nameservers_new = nm_utils_strv_dup (arr->pdata, arr->len, FALSE);
nameservers_new = nm_utils_strv_dup ((char **) arr->pdata, arr->len, FALSE);
else
nameservers_new = g_new0 (char *, 1);
}

View file

@ -3384,16 +3384,15 @@ nm_utils_strv_make_deep_copied_n (const char **strv, gsize len)
* cloned or not.
*/
char **
nm_utils_strv_dup (gpointer strv,
gssize len,
gboolean deep_copied)
_nm_utils_strv_dup (const char *const*strv,
gssize len,
gboolean deep_copied)
{
gsize i, l;
char **v;
const char *const *const src = strv;
if (len < 0)
l = NM_PTRARRAY_LEN (src);
l = NM_PTRARRAY_LEN (strv);
else
l = len;
if (l == 0) {
@ -3405,7 +3404,7 @@ nm_utils_strv_dup (gpointer strv,
v = g_new (char *, l + 1);
for (i = 0; i < l; i++) {
if (G_UNLIKELY (!src[i])) {
if (G_UNLIKELY (!strv[i])) {
/* NULL strings are not allowed. Clear the remainder of the array
* and return it (with assertion failure). */
l++;
@ -3415,9 +3414,9 @@ nm_utils_strv_dup (gpointer strv,
}
if (deep_copied)
v[i] = g_strdup (src[i]);
v[i] = g_strdup (strv[i]);
else
v[i] = (char *) src[i];
v[i] = (char *) strv[i];
}
v[l] = NULL;
return v;

View file

@ -1527,9 +1527,11 @@ nm_utils_strv_make_deep_copied_nonnull (const char **strv)
return nm_utils_strv_make_deep_copied (strv) ?: g_new0 (char *, 1);
}
char **nm_utils_strv_dup (gpointer strv,
gssize len,
gboolean deep_copied);
char **_nm_utils_strv_dup (const char *const*strv,
gssize len,
gboolean deep_copied);
#define nm_utils_strv_dup(strv, len, deep_copied) _nm_utils_strv_dup (NM_CAST_STRV_CC (strv), (len), (deep_copied))
/*****************************************************************************/