summaryrefslogtreecommitdiff
path: root/src/util/check_return.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/check_return.h')
-rw-r--r--src/util/check_return.h17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/util/check_return.h b/src/util/check_return.h
index cd2c293..89ed4bc 100644
--- a/src/util/check_return.h
+++ b/src/util/check_return.h
@@ -45,17 +45,14 @@
// CHECK_RETURN_END
//
// Allows cleanup code before return.
-#define CHECK_RETURN_BEGIN(cond, retval) \
- if (cond) {
-
+#define CHECK_RETURN_BEGIN(cond, retval) if (cond) {
#define ERROR_MSG(...) \
do { \
fprintf(stderr, "Error: " __VA_ARGS__); \
fprintf(stderr, " [%s:%d]\n", __FILE__, __LINE__); \
} while (0)
-#define CHECK_RETURN_END \
- }
+#define CHECK_RETURN_END }
// Warning message (non-fatal, execution continues)
// Usage: WARN_IF(count == 0, "No items found");
@@ -84,7 +81,6 @@
// Block-based check - cleanup code preserved, messages stripped
#define CHECK_RETURN_BEGIN(cond, retval) if (cond) {
-
#define ERROR_MSG(...) ((void)0)
#define CHECK_RETURN_END }
@@ -103,7 +99,8 @@
// CHECK_RETURN_IF:
// - Simple error checks with no cleanup needed (90% of cases)
// - Input validation: CHECK_RETURN_IF(argc < 2, 1, "Too few arguments")
-// - Null checks: CHECK_RETURN_IF(ptr == nullptr, nullptr, "Not found: %s", name)
+// - Null checks: CHECK_RETURN_IF(ptr == nullptr, nullptr, "Not found: %s",
+// name)
// - Range checks: CHECK_RETURN_IF(x < 0 || x > max, -1, "Out of range")
//
// CHECK_RETURN_BEGIN/END:
@@ -141,13 +138,15 @@
// - Programming errors (assertion failures, invariant violations)
// - Corrupted state that cannot be recovered
// - Internal consistency checks
-// - Example: FATAL_CHECK(idx >= size, "Index out of bounds: %d >= %d", idx, size)
+// - Example: FATAL_CHECK(idx >= size, "Index out of bounds: %d >= %d", idx,
+// size)
//
// Use CHECK_RETURN for:
// - Recoverable errors (invalid input, missing files)
// - Runtime configuration issues
// - API parameter validation
-// - Example: CHECK_RETURN_IF(file == nullptr, false, "File not found: %s", path)
+// - Example: CHECK_RETURN_IF(file == nullptr, false, "File not found: %s",
+// path)
//
// Key difference:
// - FATAL_XXX: abort() - program terminates