hardfault: Make Abort more useful when developing
What changed, and why it matters
This commit changes how the firmware's emergency abort function behaves only during internal software testing. When the TESTING flag is set, calling Abort() now prints the error message to standard error and exits the program, instead of hanging or triggering hardware-specific behavior. This makes debugging test failures easier and has no effect on the real device firmware.
No security action needed. This is a benign development-only change. Reviewers may verify that the TESTING guard fully prevents the new stderr/exit path from being compiled into production firmware.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies src/hardfault.c to add a TESTING-specific implementation of Abort(). Under TESTING, it includes stdio.h and stdlib.h, prints the abort message to stderr, and calls exit(1). The non-TESTING path remains unchanged: it logs to util_log, prints to screen, stops USB, closes bootloader/system interfaces, asserts false, and loops forever. The change is purely a developer-quality-of-life improvement for unit/integration tests.
Changed components
src/hardfault.cInspect captured patch +11 / −3
diff --git a/src/hardfault.c b/src/hardfault.c
index 10016b1..6bd5460 100644
--- a/src/hardfault.c
+++ b/src/hardfault.c
@@ -20,8 +20,13 @@
#include <platform_config.h>
#include <screen.h>
#include <usb/usb.h>
-#ifndef TESTING
+#if defined(TESTING)
+#include <stdio.h>
+#include <stdlib.h>
+#endif
+
+#ifndef TESTING
void HardFault_Handler(void)
{
Abort("Unexpected error.\nPlease contact support.");
@@ -35,20 +40,23 @@ void MemManage_Handler(void)
void Abort(const char* msg)
{
+#if defined(TESTING)
+ fprintf(stderr, "%s\n", msg);
+ exit(1);
+#else
util_log("%s", msg);
screen_print_debug(msg, 0);
usb_stop();
-#if !defined(TESTING)
#if defined(BOOTLOADER)
bootloader_close_interfaces();
#else
system_close_interfaces();
-#endif
#endif
// Break the program if we are debugging
ASSERT(false);
while (1) {
}
+#endif
}
void AbortAutoenter(const char* msg)
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.