[vlc-commits] [Git][videolan/vlc][master] core: use config count not size for allocating space for options
    Jean-Baptiste Kempf (@jbk) 
    gitlab at videolan.org
       
    Sat Aug  7 10:48:59 UTC 2021
    
    
  
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
d4ea6d02 by Lyndon Brown at 2021-08-07T07:53:09+00:00
core: use config count not size for allocating space for options
`size` counts both actual options **and** hint entries within option
sets. `count` only counts the actual options. we are only interested in
the actual options here, so we should use `count` to allocate only the
memory we actually need. this avoids allocating roughly 1000 pointers'
worth of unused space.
the addition of the assert was requested in review.
- - - - -
1 changed file:
- src/config/core.c
Changes:
=====================================
src/config/core.c
=====================================
@@ -410,13 +410,13 @@ int config_SortConfig (void)
     size_t nconf = 0;
 
     for (p = vlc_plugins; p != NULL; p = p->next)
-         nconf += p->conf.size;
+        nconf += p->conf.count;
 
     module_config_t **clist = vlc_alloc (nconf, sizeof (*clist));
     if (unlikely(clist == NULL))
         return VLC_ENOMEM;
 
-    nconf = 0;
+    size_t index = 0;
     for (p = vlc_plugins; p != NULL; p = p->next)
     {
         module_config_t *item, *end;
@@ -427,7 +427,8 @@ int config_SortConfig (void)
         {
             if (!CONFIG_ITEM(item->i_type))
                 continue; /* ignore hints */
-            clist[nconf++] = item;
+            assert(index < nconf);
+            clist[index++] = item;
         }
     }
 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/d4ea6d025363f6cd1eb928d32733ce3a31f89ed1
-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/d4ea6d025363f6cd1eb928d32733ce3a31f89ed1
You're receiving this email because of your account on code.videolan.org.
    
    
More information about the vlc-commits
mailing list