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++)
{
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++)
{
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
/* 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;