diff --git a/storm/Error.cpp b/storm/Error.cpp index e984f71..6a9f086 100644 --- a/storm/Error.cpp +++ b/storm/Error.cpp @@ -9,6 +9,7 @@ static uint32_t s_lasterror = ERROR_SUCCESS; static int32_t s_suppress; +static int32_t s_displaying; [[noreturn]] void STORMCDECL SErrDisplayAppFatal(const char* format, ...) { va_list args; @@ -21,6 +22,9 @@ static int32_t s_suppress; } int32_t STORMAPI SErrDisplayError(uint32_t errorcode, const char* filename, int32_t linenumber, const char* description, int32_t recoverable, uint32_t exitcode, uint32_t a7) { + if (s_suppress || s_displaying) return 0; + s_displaying = 1; + // TODO printf("\n=========================================================\n"); @@ -53,11 +57,12 @@ int32_t STORMAPI SErrDisplayError(uint32_t errorcode, const char* filename, int3 printf(" Assertion: %s\n", description); } - if (recoverable) { - return 1; - } else { - exit(exitcode); + s_displaying = 0; + if (!recoverable) { + SErrSuppressErrors(1); + std::exit(exitcode); } + return 1; } int32_t STORMCDECL SErrDisplayErrorFmt(uint32_t errorcode, const char* filename, int32_t linenumber, int32_t recoverable, uint32_t exitcode, const char* format, ...) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f0fa916..38ff1da 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,6 @@ if(WHOA_TEST_STORMDLL) + # Note: Error excluded because some functions take more args than expected by older Storms set(TEST_SOURCES Big.cpp Core.cpp diff --git a/test/Error.cpp b/test/Error.cpp new file mode 100644 index 0000000..54c6fd5 --- /dev/null +++ b/test/Error.cpp @@ -0,0 +1,14 @@ +#include "test/Test.hpp" +#include "storm/Error.hpp" + +TEST_CASE("SErrDisplayError", "[event]") { + SECTION("does nothing if errors are suppressed") { + uint32_t errorcode = GENERATE(0, STORM_ERROR_ASSERTION, ERROR_INVALID_PARAMETER); + int32_t recoverable = GENERATE(0, 1); + uint32_t exitcode = GENERATE(0, 1); + uint32_t unkarg = GENERATE(0, 1, 0x11111111); + + SErrSuppressErrors(1); + CHECK_FALSE(SErrDisplayError(errorcode, nullptr, 0, nullptr, recoverable, exitcode, unkarg)); + } +} diff --git a/test/stormdll/stormstubs.cpp b/test/stormdll/stormstubs.cpp index aa0bfc4..5d88c92 100644 --- a/test/stormdll/stormstubs.cpp +++ b/test/stormdll/stormstubs.cpp @@ -36,7 +36,7 @@ void STORMAPI SBigToUnsigned(BigData*, uint32_t*) {} #include void STORMCDECL SErrDisplayAppFatal(const char* format, ...) {} -int32_t STORMAPI SErrDisplayError(uint32_t, const char*, int32_t, const char*, int32_t, uint32_t, uint32_t) { return 0; } +int32_t STORMAPI SErrDisplayError(uint32_t, const char*, int32_t, const char*, int32_t, uint32_t) { return 0; } int32_t STORMCDECL SErrDisplayErrorFmt(uint32_t, const char*, int32_t, int32_t, uint32_t, const char*, ...) { return 0; } void STORMAPI SErrPrepareAppFatal(const char*, int32_t) {} void STORMAPI SErrSetLastError(uint32_t) {}