From: Michael Brown Date: Fri, 9 May 2025 11:03:29 +0000 (+0100) Subject: [libc] Display assertion failure message before incrementing counter X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=1d58d928fe97e9095e7e91b727ea36fcea9d2567;p=thirdparty%2Fipxe.git [libc] Display assertion failure message before incrementing counter During early initialisation on some platforms, the .data and .bss sections may not yet be writable. Display the assertion message before attempting to increment the assertion failure counter, since writing to the assertion counter may trigger a CPU exception that ends up resetting the system. Signed-off-by: Michael Brown --- diff --git a/src/include/assert.h b/src/include/assert.h index 01a287855..5affab2db 100644 --- a/src/include/assert.h +++ b/src/include/assert.h @@ -49,9 +49,9 @@ assert_printf ( const char *fmt, ... ) asm ( "printf" ); #define assert( condition ) \ do { \ if ( ASSERTING && ! (condition) ) { \ - assertion_failures++; \ assert_printf ( "assert(%s) failed at %s line %d\n", \ #condition, __FILE__, __LINE__ ); \ + assertion_failures++; \ } \ } while ( 0 )