Commit 1b8b05c7 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

config: simplify a bit

parent 1637adb2
......@@ -356,10 +356,8 @@ ssize_t config_GetIntChoices (vlc_object_t *obj, const char *name,
if (count == 0)
return 0;
int64_t *vals = malloc (sizeof (*vals) * count);
char **txts = malloc (sizeof (*txts) * count);
if (unlikely(vals == NULL || txts == NULL))
abort ();
int64_t *vals = xmalloc (sizeof (*vals) * count);
char **txts = xmalloc (sizeof (*txts) * count);
for (size_t i = 0; i < count; i++)
{
......@@ -406,10 +404,8 @@ ssize_t config_GetPszChoices (vlc_object_t *obj, const char *name,
return cfg->list.psz_cb(obj, name, values, texts);
}
char **vals = malloc (sizeof (*vals) * count);
char **txts = malloc (sizeof (*txts) * count);
if (unlikely(vals == NULL || txts == NULL))
abort ();
char **vals = xmalloc (sizeof (*vals) * count);
char **txts = xmalloc (sizeof (*txts) * count);
for (size_t i = 0; i < count; i++)
{
......
......@@ -379,31 +379,25 @@ static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...)
assert (item->list_count == 0); /* cannot replace choices */
assert (item->list.psz_cb == NULL);
if (len == 0)
break; /* nothing to do */
/* Copy values */
if (IsConfigIntegerType (item->i_type))
{
const int *src = va_arg (ap, const int *);
int *dst = malloc (sizeof (int) * (len + 1));
int *dst = xmalloc (sizeof (int) * len);
if (dst != NULL)
{
memcpy (dst, src, sizeof (int) * len);
dst[len] = 0;
}
memcpy (dst, src, sizeof (int) * len);
item->list.i = dst;
}
else
if (IsConfigStringType (item->i_type))
{
const char *const *src = va_arg (ap, const char *const *);
char **dst = malloc (sizeof (char *) * (len + 1));
if (dst != NULL)
{
for (size_t i = 0; i < len; i++)
dst[i] = src[i] ? strdup (src[i]) : NULL;
dst[len] = NULL;
}
char **dst = xmalloc (sizeof (char *) * len);
for (size_t i = 0; i < len; i++)
dst[i] = src[i] ? strdup (src[i]) : NULL;
item->list.psz = dst;
}
else
......@@ -411,13 +405,9 @@ static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...)
/* Copy textual descriptions */
const char *const *text = va_arg (ap, const char *const *);
char **dtext = malloc (sizeof (char *) * (len + 1));
if( dtext != NULL )
{
for (size_t i = 0; i < len; i++)
dtext[i] = text[i] ? strdup (text[i]) : NULL;
dtext[len] = NULL;
}
char **dtext = xmalloc (sizeof (char *) * (len + 1));
for (size_t i = 0; i < len; i++)
dtext[i] = text[i] ? strdup (text[i]) : NULL;
item->list_text = dtext;
item->list_count = len;
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment