Use dynamic memory allocation instead of variable-length arrays

Since it is easy to trigger a stack overflow with variable-length arrays,
use dynamic memory allocation instead of VLAs. Add -Wvla to the compiler
options such that no new VLAs get introduced.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
This commit is contained in:
Bart Van Assche
2019-11-03 14:12:20 -08:00
parent 88f67e8cf8
commit 9d2493248b
9 changed files with 70 additions and 17 deletions

View File

@@ -28,7 +28,7 @@ AC_ARG_ENABLE([werror], [AS_HELP_STRING([--disable-werror],
[Disables building with -Werror by default])])
if test "$ac_cv_prog_gcc" = yes; then
WARN_CFLAGS="-Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wno-strict-aliasing"
WARN_CFLAGS="-Wall -W -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wno-strict-aliasing -Wvla"
WARN_CFLAGS="$WARN_CFLAGS -Wno-unknown-warning-option -Wno-stringop-truncation"
if test "x$enable_werror" != "xno"; then
WARN_CFLAGS="$WARN_CFLAGS -Werror"