]> granicus.if.org Git - php/commitdiff
Add check for variable size array feature
authorAnatol Belski <ab@php.net>
Sat, 9 Jun 2018 18:27:16 +0000 (20:27 +0200)
committerAnatol Belski <ab@php.net>
Sat, 9 Jun 2018 18:27:16 +0000 (20:27 +0200)
Usage of VLA is not portable, wile supported by some compilers. For
instance, GCC supports it even if -std=c89 is passed. Even if we would
switch to C99, it would be still not portable at least with VC++. Thus,
adding a centralized check so such code can be guarded and moved to
alloca() if needed.

configure.ac
ext/mysqlnd/mysqlnd_wireprotocol.c

index e18e1de2efb4ec33139b8e8036aeb8f0b51b1f3e..4a59831cc260db86f7e7e148ff0580c229366b62 100644 (file)
@@ -784,6 +784,20 @@ if test "$ac_cv__asm_goto" = yes; then
   AC_DEFINE(HAVE_ASM_GOTO,1,[Define if asm goto support])
 fi
 
+dnl Check for variable length array support
+AC_CACHE_CHECK([whether compiler supports VLA], ac_cv__compiler_c99_vla,
+[AC_TRY_RUN([
+ #include <stdlib.h>
+ int main(void) {
+         int i[rand()%10];
+        return 0;
+ }
+ ],ac_cv__compiler_c99_vla=yes, ac_cv__compiler_c99_vla=no, ac_cv__compiler_c99_vla=no)])
+
+if test "$ac_cv__compiler_c99_vla" = yes; then
+       AC_DEFINE(HAVE_COMPILER_C99_VLA, 1, [Compiler supports VLA])
+fi
+
 dnl Check valgrind support
 PHP_ARG_WITH(valgrind, [whether to enable valgrind support],
 [  --with-valgrind=DIR     Enable valgrind support], yes, no)
index 0aee0d9b94b0b632362ca827524fe79e07fc3891..20b82ac6582c6c8652474622c5d44c8af43b3112 100644 (file)
@@ -2162,7 +2162,7 @@ size_t php_mysqlnd_cached_sha2_result_write(MYSQLND_CONN_DATA * conn, void * _pa
        MYSQLND_PFC * pfc = conn->protocol_frame_codec;
        MYSQLND_VIO * vio = conn->vio;
        MYSQLND_STATS * stats = conn->stats;
-#ifndef _MSC_VER
+#if HAVE_COMPILER_C99_VLA
        zend_uchar buffer[MYSQLND_HEADER_SIZE + packet->password_len + 1];
 #else
        ALLOCA_FLAG(use_heap)
@@ -2180,7 +2180,7 @@ size_t php_mysqlnd_cached_sha2_result_write(MYSQLND_CONN_DATA * conn, void * _pa
                sent = pfc->data->m.send(pfc, vio, buffer, packet->password_len, stats, error_info);
        }
 
-#ifdef _MSC_VER
+#if !HAVE_COMPILER_C99_VLA
        free_alloca(buffer, use_heap);
 #endif