From 06f7387466eb7d9ee3d9963d3a52a8f455bcaaf2 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 6 Oct 2020 03:04:25 +0200 Subject: [PATCH] Avoid using VLA in EQUS dumping MSVC does not support those... Also add a `develop` warning about VLAs, to avoid future incidents --- CMakeLists.txt | 2 +- Makefile | 2 +- src/asm/lexer.c | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc0de9bf..debc225b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ else() if(MORE_WARNINGS) add_compile_options(-Werror -Wextra -Wno-type-limits - -Wno-sign-compare -Wformat -Wformat-security -Wformat-overflow=2 + -Wno-sign-compare -Wvla -Wformat -Wformat-security -Wformat-overflow=2 -Wformat-truncation=1 -Wformat-y2k -Wswitch-enum -Wunused -Wuninitialized -Wunknown-pragmas -Wstrict-overflow=5 -Wstringop-overflow=4 -Walloc-zero -Wduplicated-cond diff --git a/Makefile b/Makefile index ee66e399..16581a7d 100644 --- a/Makefile +++ b/Makefile @@ -187,7 +187,7 @@ checkpatch: develop: $Qenv $(MAKE) -j WARNFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-type-limits \ - -Wno-sign-compare -Wformat -Wformat-security -Wformat-overflow=2 \ + -Wno-sign-compare -Wvla -Wformat -Wformat-security -Wformat-overflow=2 \ -Wformat-truncation=1 -Wformat-y2k -Wswitch-enum -Wunused \ -Wuninitialized -Wunknown-pragmas -Wstrict-overflow=5 \ -Wstringop-overflow=4 -Walloc-zero -Wduplicated-cond \ diff --git a/src/asm/lexer.c b/src/asm/lexer.c index d5cfa1c1..d6834d41 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -897,11 +897,14 @@ void lexer_DumpStringExpansions(void) { if (!lexerState) return; - struct Expansion *stack[nMaxRecursionDepth + 1]; + struct Expansion **stack = malloc(sizeof(*stack) * (nMaxRecursionDepth + 1)); struct Expansion *expansion; /* Temp var for `lookupExpansion` */ unsigned int depth = 0; size_t distance = lexerState->expansionOfs; + if (!stack) + fatalerror("Failed to alloc string expansion stack: %s\n", strerror(errno)); + #define LOOKUP_PRE_NEST(exp) do { \ /* Only register EQUS expansions, not string args */ \ if ((exp)->name) \ @@ -915,6 +918,7 @@ void lexer_DumpStringExpansions(void) while (depth--) fprintf(stderr, "while expanding symbol \"%s\"\n", stack[depth]->name); + free(stack); } /* Function to discard all of a line's comments */