[vlc-commits] [Git][videolan/vlc][master] gnutls: avoid using realloc for a fixed size

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Jan 20 10:27:42 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
6d7ce219 by Steve Lhomme at 2023-01-20T09:54:39+00:00
gnutls: avoid using realloc for a fixed size

This also fixes a (bogus) warning in gcc with the realloc usage.

- - - - -


1 changed file:

- modules/misc/gnutls.c


Changes:

=====================================
modules/misc/gnutls.c
=====================================
@@ -266,22 +266,24 @@ static vlc_tls_gnutls_t *gnutls_SessionOpen(vlc_object_t *obj, int type,
 
     if (alpn != NULL)
     {
-        gnutls_datum_t *protv = NULL;
-        unsigned protc = 0;
+        gnutls_datum_t *protv;
+        size_t protc = 0;
+        const char *const *alpn_count = alpn;
 
-        while (*alpn != NULL)
+        while (*alpn_count != NULL)
         {
-            gnutls_datum_t *n = realloc(protv, sizeof (*protv) * (protc + 1));
-            if (unlikely(n == NULL))
-            {
-                free(protv);
-                goto error;
-            }
-            protv = n;
-
-            protv[protc].data = (void *)*alpn;
-            protv[protc].size = strlen(*alpn);
             protc++;
+            alpn_count++;
+        }
+
+        protv = vlc_alloc(protc, sizeof (*protv));
+        if (unlikely(protv == NULL))
+            goto error;
+
+        for (size_t i=0; i < protc; i++)
+        {
+            protv[i].data = (void *)*alpn;
+            protv[i].size = strlen(*alpn);
             alpn++;
         }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6d7ce21912cf87aa58012ad484b14be853236a38

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6d7ce21912cf87aa58012ad484b14be853236a38
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list