Crash (stack corruption) on failed assert_int_equal on windows (mingw)
I'm seeing the following code crash when compiled for windows using mingw:
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include "cmocka.h"
enum RESULTCODE {
VAL1, VAL2
};
static void test_enum_compare(void **state) {
(void) state; // unused
assert_int_equal(1, VAL1);
assert_int_equal(1, 1);
}
int main(void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup(test_enum_compare, NULL)
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
This crashes on Windows, producing a corrupted stack:
Faulting application name: test_enum_windows.exe, version: 0.0.0.0, time stamp: 0x619f8673
Faulting module name: ntdll.dll, version: 10.0.19041.1202, time stamp: 0x4f115fac
Exception code: 0xc0000028
Fault offset: 0x0000000000102346
Faulting process id: 0x1570
Faulting application start time: 0x01d7e1faf820e357
Faulting application path: C:\vagrant\test_enum_windows.exe
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
Unhandled exception at 0x00007FF9B8692346 (ntdll.dll) in
test_clone.exe: 0xC0000028: An invalid or unaligned stack was
encountered during an unwind operation.
ntdll.dll!00007ff9b8692346() Unknown
ntdll.dll!00007ff9b85c0bb3() Unknown
msvcrt.dll!00007ff9b74b2eed() Unknown
test_enum_windows.exe!exit_test(volatile int quit_application) Line 407 C++
test_enum_windows.exe!_fail(volatile char * volatile file, volatile int line) Line 2197 C++
test_enum_windows.exe!_assert_int_equal(volatile unsigned __int64 a, volatile unsigned __int64 b, volatile char * volatile file, volatile int line) Line 1802 C++
...
Note that if the assertion succeeds there is no crash. Additionally this does not fail when the same code is built and run for linux.
I used this command to build the test (using https://hub.docker.com/r/mmozeiko/mingw-w64):
docker run -v${WORKDIR}:${WORKDIR} -w${WORKDIR} mmozeiko/mingw-w64 /usr/local/bin/x86_64-w64-mingw32-gcc test_enum.c -L build/cmocka-1.1.5/windows/x86_64-debug/lib/ -lcmocka-static -Icmocka-1.1.5/include/ -o test_enum_windows.exe
And the following vagrant vm to test it:
Edited by John J