diff --git a/Libraries/LibC/assert.cpp b/Libraries/LibC/assert.cpp index ae4ddfe7df..9e84b22cd6 100644 --- a/Libraries/LibC/assert.cpp +++ b/Libraries/LibC/assert.cpp @@ -27,15 +27,18 @@ #include #include #include +#include #include extern "C" { +extern bool __stdio_is_initialized; #ifdef DEBUG void __assertion_failed(const char* msg) { dbgprintf("USERSPACE(%d) ASSERTION FAILED: %s\n", getpid(), msg); - fprintf(stderr, "ASSERTION FAILED: %s\n", msg); + if (__stdio_is_initialized) + fprintf(stderr, "ASSERTION FAILED: %s\n", msg); abort(); } #endif diff --git a/Libraries/LibC/libcinit.cpp b/Libraries/LibC/libcinit.cpp index 22e7eb62e9..7e38ebc36f 100644 --- a/Libraries/LibC/libcinit.cpp +++ b/Libraries/LibC/libcinit.cpp @@ -34,6 +34,7 @@ extern "C" { __thread int errno; char** environ; bool __environ_is_malloced; +bool __stdio_is_initialized; void __libc_init() { diff --git a/Libraries/LibC/stdio.cpp b/Libraries/LibC/stdio.cpp index f39a7f0639..02f8b76702 100644 --- a/Libraries/LibC/stdio.cpp +++ b/Libraries/LibC/stdio.cpp @@ -585,6 +585,7 @@ void __stdio_init() new (stdout) FILE(1, O_WRONLY); new (stderr) FILE(2, O_WRONLY); stderr->setbuf(nullptr, _IONBF, 0); + __stdio_is_initialized = true; } int setvbuf(FILE* stream, char* buf, int mode, size_t size) diff --git a/Libraries/LibC/sys/internals.h b/Libraries/LibC/sys/internals.h index 0ddde4037b..70443404e1 100644 --- a/Libraries/LibC/sys/internals.h +++ b/Libraries/LibC/sys/internals.h @@ -37,6 +37,7 @@ extern void __malloc_init(); extern void __stdio_init(); extern void _init(); extern bool __environ_is_malloced; +extern bool __stdio_is_initialized; int __cxa_atexit(AtExitFunction exit_function, void* parameter, void* dso_handle); void __cxa_finalize(void* dso_handle);