]> granicus.if.org Git - gc/commitdiff
Workaround 'obsolete function alloca() called' cppcheck warnings
authorIvan Maidanski <ivmai@mail.ru>
Tue, 18 Oct 2016 09:24:34 +0000 (12:24 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 18 Oct 2016 09:24:34 +0000 (12:24 +0300)
* dyn_load.c [AIX] (GC_register_dynamic_libraries): Code refactoring
to have alloca() call only once (at the beginning of a block); use
variable-length array instead of alloca() if CPPCHECK.

dyn_load.c

index 558fb88701b42b89fff81dcc75a8ac0a81d4cb7e..90b670b16e5da3d2fbf5db9cfd58f08313c708e9 100644 (file)
@@ -1179,18 +1179,24 @@ GC_INNER void GC_register_dynamic_libraries(void)
 # include <sys/errno.h>
   GC_INNER void GC_register_dynamic_libraries(void)
   {
+      int ldibuflen = 8192;
+
+      for (;;) {
         int len;
-        char *ldibuf;
-        int ldibuflen;
         struct ld_info *ldi;
+#       if defined(CPPCHECK)
+          char ldibuf[ldibuflen];
+#       else
+          char *ldibuf = alloca(ldibuflen);
+#       endif
 
-        ldibuf = alloca(ldibuflen = 8192);
-
-        while ( (len = loadquery(L_GETINFO,ldibuf,ldibuflen)) < 0) {
+        len = loadquery(L_GETINFO, ldibuf, ldibuflen);
+        if (len < 0) {
                 if (errno != ENOMEM) {
                         ABORT("loadquery failed");
                 }
-                ldibuf = alloca(ldibuflen *= 2);
+                ldibuflen *= 2;
+                continue;
         }
 
         ldi = (struct ld_info *)ldibuf;
@@ -1203,6 +1209,8 @@ GC_INNER void GC_register_dynamic_libraries(void)
                                 TRUE);
                 ldi = len ? (struct ld_info *)((char *)ldi + len) : 0;
         }
+        break;
+      }
   }
 #endif /* AIX */