build: add build support for enforcing return codes are checked
What changed, and why it matters
This commit adds compiler flags and helper macros to make the build fail whenever a function's return value is ignored without explicit intent. It is a hardening change, not a fix for a specific known bug. By enforcing that programmers check or deliberately discard return values, it reduces the chance that silent failures (for example, a failed security check or memory operation) slip into future code. There is no direct evidence in the commit that an existing vulnerability is being patched.
Treat as a proactive hardening commit. Review whether existing code compiles cleanly under the new flag and ensure IGNORE_RESULT is used sparingly and only after risk review. Monitor subsequent commits that annotate functions with WARN_UNUSED_RESULT for any latent unchecked-return bugs they may surface.
Security signals we found
Compiler hardening flag added (-Werror=unused-result)
New macros to annotate and explicitly ignore function return values
No specific vulnerable call site patched in this commit
No vendor security disclosure or CVE referenced in commit message
Evidence from the diff
The change introduces -Werror=unused-result in libjade/CMakeLists.txt, main/CMakeLists.txt, and adds WARN_UNUSED_RESULT and IGNORE_RESULT macros in main/jade_assert.h. -Werror=unused-result turns the compiler’s ‘warn_unused_result’ attribute warning into a build error, and the macros allow marking functions whose return values must be checked and explicitly silencing the warning when a result is intentionally discarded. This is a build-time/static-analysis hardening measure. The diff does not modify any runtime logic, fix a specific unchecked return, or reference a CVE or security report.
Changed components
libjade/CMakeLists.txtmain/CMakeLists.txtmain/jade_assert.hFuture Jade/libjade source code compiled with these targetsInspect captured patch +21 / −0
diff --git a/libjade/CMakeLists.txt b/libjade/CMakeLists.txt
index 42bf6a4..c0d61a7 100644
--- a/libjade/CMakeLists.txt
+++ b/libjade/CMakeLists.txt
@@ -145,3 +145,7 @@ add_custom_command(OUTPUT asset_data_testnet.inc
add_custom_target(asset_data DEPENDS asset_data.inc asset_data_testnet.inc)
add_dependencies(jade asset_data)
add_dependencies(jade_static asset_data)
+
+target_compile_options(jade PRIVATE -Werror=unused-result)
+target_compile_options(jade_static PRIVATE -Werror=unused-result)
+target_compile_options(libjade_daemon PRIVATE -Werror=unused-result)
\ No newline at end of file
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index f2a49f7..724e012 100755
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -84,3 +84,5 @@ endif()
target_link_libraries(${COMPONENT_TARGET} "-u custom_app_desc")
list(APPEND link_options "-Wl,--wrap=abort")
idf_build_set_property(LINK_OPTIONS "${link_options}" APPEND)
+
+target_compile_options(${COMPONENT_LIB} PRIVATE -Werror=unused-result)
\ No newline at end of file
diff --git a/main/jade_assert.h b/main/jade_assert.h
index 26b2554..b25f40a 100644
--- a/main/jade_assert.h
+++ b/main/jade_assert.h
@@ -85,4 +85,19 @@ void __wrap_abort(void);
JADE_LOGD("Released mutex %p", (void*)s); \
} while (false)
+// Warn if a function return value is unused.
+#ifndef WARN_UNUSED_RESULT
+#define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
+#endif
+
+// Deliberately ignores result of a function
+#ifndef IGNORE_RESULT
+#define IGNORE_RESULT(x) \
+ do { \
+ if ((x)) { \
+ (void)0; \
+ } \
+ } while (0)
+#endif
+
#endif // JADE_ASSERT_H_
Why this scored 26/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.