Skip to content

Commit c79af09

Browse files
committed
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.
1 parent d877d18 commit c79af09

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

configure.ac

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,20 @@ if test "$ac_cv__asm_goto" = yes; then
784784
AC_DEFINE(HAVE_ASM_GOTO,1,[Define if asm goto support])
785785
fi
786786

787+
dnl Check for variable length array support
788+
AC_CACHE_CHECK([whether compiler supports VLA], ac_cv__compiler_c99_vla,
789+
[AC_TRY_RUN([
790+
#include <stdlib.h>
791+
int main(void) {
792+
int i[rand()%10];
793+
return 0;
794+
}
795+
],ac_cv__compiler_c99_vla=yes, ac_cv__compiler_c99_vla=no, ac_cv__compiler_c99_vla=no)])
796+
797+
if test "$ac_cv__compiler_c99_vla" = yes; then
798+
AC_DEFINE(HAVE_COMPILER_C99_VLA, 1, [Compiler supports VLA])
799+
fi
800+
787801
dnl Check valgrind support
788802
PHP_ARG_WITH(valgrind, [whether to enable valgrind support],
789803
[ --with-valgrind=DIR Enable valgrind support], yes, no)

ext/mysqlnd/mysqlnd_wireprotocol.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,7 +2162,7 @@ size_t php_mysqlnd_cached_sha2_result_write(MYSQLND_CONN_DATA * conn, void * _pa
21622162
MYSQLND_PFC * pfc = conn->protocol_frame_codec;
21632163
MYSQLND_VIO * vio = conn->vio;
21642164
MYSQLND_STATS * stats = conn->stats;
2165-
#ifndef _MSC_VER
2165+
#if HAVE_COMPILER_C99_VLA
21662166
zend_uchar buffer[MYSQLND_HEADER_SIZE + packet->password_len + 1];
21672167
#else
21682168
ALLOCA_FLAG(use_heap)
@@ -2180,7 +2180,7 @@ size_t php_mysqlnd_cached_sha2_result_write(MYSQLND_CONN_DATA * conn, void * _pa
21802180
sent = pfc->data->m.send(pfc, vio, buffer, packet->password_len, stats, error_info);
21812181
}
21822182

2183-
#ifdef _MSC_VER
2183+
#if !HAVE_COMPILER_C99_VLA
21842184
free_alloca(buffer, use_heap);
21852185
#endif
21862186

0 commit comments

Comments
 (0)