From edd98e89ab2332eadc7eb14e239374a5f1900800 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Tue, 18 Oct 2016 12:24:34 +0300 Subject: [PATCH] Workaround 'obsolete function alloca() called' cppcheck warnings * 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 | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/dyn_load.c b/dyn_load.c index 558fb887..90b670b1 100644 --- a/dyn_load.c +++ b/dyn_load.c @@ -1179,18 +1179,24 @@ GC_INNER void GC_register_dynamic_libraries(void) # include 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 */ -- 2.40.0