From c79af09bc6ec017fe70ebc8534c90e6993f39ce2 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 9 Jun 2018 20:27:16 +0200 Subject: [PATCH] Add check for variable size array feature 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 | 14 ++++++++++++++ ext/mysqlnd/mysqlnd_wireprotocol.c | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index e18e1de2ef..4a59831cc2 100644 --- a/configure.ac +++ b/configure.ac @@ -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 + 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) diff --git a/ext/mysqlnd/mysqlnd_wireprotocol.c b/ext/mysqlnd/mysqlnd_wireprotocol.c index 0aee0d9b94..20b82ac658 100644 --- a/ext/mysqlnd/mysqlnd_wireprotocol.c +++ b/ext/mysqlnd/mysqlnd_wireprotocol.c @@ -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 -- 2.40.0