]> git.sesse.net Git - vlc/commitdiff
config: simplify a bit
authorRémi Denis-Courmont <remi@remlab.net>
Fri, 24 Aug 2012 11:21:40 +0000 (14:21 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Fri, 24 Aug 2012 11:22:43 +0000 (14:22 +0300)
src/config/core.c
src/modules/entry.c

index d5c108e09d3200f847f12ef9a2aade6e5a77b68f..148d6edebf99c30c7be6458f9fbf4096c9fd217a 100644 (file)
@@ -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++)
     {
index f9df6ee3d18d343d5667221ee6dcfd1e1321bd32..33dc46d9d1102c3161d380fb592b33c9450d6834 100644 (file)
@@ -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;