Skip to content

Commit 3db53eb

Browse files
committed
common: update the error checking macros
1 parent df4448f commit 3db53eb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/common.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,16 @@
121121
/**
122122
* Check a pointer allocation result, returning -1 if it failed.
123123
*/
124-
#define GIT_ERROR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; }
124+
#define GIT_ERROR_CHECK_ALLOC(ptr) do { \
125+
if ((ptr) == NULL) { return -1; } \
126+
} while(0)
125127

126128
/**
127129
* Check a string buffer allocation result, returning -1 if it failed.
128130
*/
129-
#define GIT_ERROR_CHECK_ALLOC_STR(buf) if ((void *)(buf) == NULL || git_str_oom(buf)) { return -1; }
131+
#define GIT_ERROR_CHECK_ALLOC_STR(buf) do { \
132+
if ((void *)(buf) == NULL || git_str_oom(buf)) { return -1; } \
133+
} while(0)
130134

131135
/**
132136
* Check a return value and propagate result if non-zero.

0 commit comments

Comments
 (0)