]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[libc] Display assertion failure message before incrementing counter
authorMichael Brown <mcb30@ipxe.org>
Fri, 9 May 2025 11:03:29 +0000 (12:03 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 9 May 2025 13:36:00 +0000 (14:36 +0100)
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 <mcb30@ipxe.org>
src/include/assert.h

index 01a287855189eb40e008bcc43842b98003cbdeec..5affab2db51945d7f38242d2b86a2293436622ba 100644 (file)
@@ -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 )