Skip to content

Commit 0f353a9

Browse files
Update cnullptr.h
1 parent f4e6896 commit 0f353a9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

code/logic/fossil/sys/cnullptr.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <stdint.h>
1818
#include <stddef.h>
19+
#include <assert.h>
1920

2021
#ifdef __cplusplus
2122
extern "C" {
@@ -85,6 +86,17 @@ extern "C" {
8586
*/
8687
#define cmaybe(ptr, default_val) ((ptr) ? (ptr) : (default_val))
8788

89+
/**
90+
* @brief Unwraps a pointer, asserting that it is not null.
91+
*
92+
* If the pointer is null, the program will terminate with an assertion failure.
93+
* Otherwise, it returns the pointer itself for safe dereferencing.
94+
*
95+
* @param ptr The pointer to unwrap.
96+
* @return The unwrapped pointer if it is not null.
97+
*/
98+
#define cunwrap(ptr) (assert((ptr) != cnull), (ptr))
99+
88100
/**
89101
* @brief Marks a variable as unused to suppress compiler warnings.
90102
*

0 commit comments

Comments
 (0)