[vlc-commits] config: simplify a bit

Rémi Denis-Courmont git at videolan.org
Fri Aug 24 13:22:46 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Aug 24 14:21:40 2012 +0300| [1b8b05c72297c19f04b2472f1ad3f04b91cecd9a] | committer: Rémi Denis-Courmont

config: simplify a bit

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1b8b05c72297c19f04b2472f1ad3f04b91cecd9a
---

 src/config/core.c   |   12 ++++--------
 src/modules/entry.c |   32 +++++++++++---------------------
 2 files changed, 15 insertions(+), 29 deletions(-)

diff --git a/src/config/core.c b/src/config/core.c
index d5c108e..148d6ed 100644
--- a/src/config/core.c
+++ b/src/config/core.c
@@ -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++)
     {
diff --git a/src/modules/entry.c b/src/modules/entry.c
index f9df6ee..33dc46d 100644
--- a/src/modules/entry.c
+++ b/src/modules/entry.c
@@ -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;



More information about the vlc-commits mailing list