Menu

#1031 abort is called from assert realization when ignore is used

v1.0 (example)
open
nobody
None
5
2026-08-06
2026-08-06
No

Code:

#include <windows.h>
#include <assert.h>

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
    assert(false);
    return 0;
}

Compile: g++ -g -o test main.cpp -mwindows
Running under gdb, Ignore button is pressed in assertion dialog, result: abort exit code (3):

warning: Invalid parameter passed to C runtime function.
warning: Invalid parameter passed to C runtime function.
warning: Invalid parameter passed to C runtime function.
[Inferior 1 (process 2748) exited with code 03]

abort is called from _assert realization:

#0  0x000007fefce55383 in msvcrt!abort () from C:\Windows\system32\msvcrt.dll
#1  0x000000013ff51da7 in _assert (message=0x13ff53078 <refptr._newmode+8> "false", file=0x13ff5307e <refptr._newmode+14> "main.cpp", line=6)
#2  0x000000013ff51499 in WinMain () at main.cpp:6
#3  0x000000013ff51cf5 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at ../crt/crtexewin.c:62

_assert code:

if (_setmode (fd, oldmode) != _O_TEXT) {
  abort ();
}

_setmode is called with fd=-2 and returns -1:

Breakpoint 1, 0x000007fefce23623 in msvcrt!_setmode () from C:\Windows\system32\msvcrt.dll
(gdb) info registers rcx rdx
rcx            0xfffffffe          4294967294
rdx            0xffffffff          4294967295
(gdb) finish
Run till exit from #0  0x000007fefce23623 in msvcrt!_setmode () from C:\Windows\system32\msvcrt.dll
0x000000013f1e1d8e in _assert (message=0x13f1e3078 <refptr._newmode+8> "false", file=0x13f1e307e <refptr._newmode+14> "main.cpp", line=6)
(gdb) info registers eax
eax            0xffffffff          -1

fd is populated from stderr which is not associated with an output stream in GUI app:

FILE *stream = stderr;
/* Cache fd used by `stderr` */
int fd = _fileno (stream);

mingw-w64 hash: 5ea8e9facd013b815f5f29f20ef26a566319a3de

Discussion


Log in to post a comment.