Skip to content

Commit 7488705

Browse files
committed
Add guidelines for the GIT_WARN_UNUSED_RESULT annotation
1 parent 4bb1568 commit 7488705

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

include/git2/common.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,18 @@ typedef size_t size_t;
7171
# define GIT_FORMAT_PRINTF(a,b) /* empty */
7272
#endif
7373

74-
/** Declare that a function's return value must be used. */
74+
/**
75+
* Declare that a function's return value must be used.
76+
*
77+
* Used mostly to guard against potential silent bugs at runtime. This is
78+
* recommended to be added to functions that:
79+
*
80+
* - Allocate / reallocate memory. This prevents memory leaks or errors where
81+
* buffers are expected to have grown to a certain size, but could not be
82+
* resized.
83+
* - Acquire locks. When a lock cannot be acquired, that will almost certainly
84+
* cause a data race / undefined behavior.
85+
*/
7586
#if defined(__GNUC__)
7687
# define GIT_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
7788
#else

0 commit comments

Comments
 (0)