summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlhchavez <lhchavez@lhchavez.com>2021-03-04 06:19:49 -0800
committerlhchavez <lhchavez@lhchavez.com>2021-08-08 19:08:59 -0700
commit7488705d45161fa8c6945a67570ac8d9fc2d7bfc (patch)
tree4b475852291f07000bb8b674767f0460211be4d5
parent4bb1568f22b03642cc160aecab1c1e15093ec748 (diff)
downloadlibgit2-7488705d45161fa8c6945a67570ac8d9fc2d7bfc.tar.gz
Add guidelines for the GIT_WARN_UNUSED_RESULT annotation
-rw-r--r--include/git2/common.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/include/git2/common.h b/include/git2/common.h
index 5f64a37f8..a6069e36e 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -71,7 +71,18 @@ typedef size_t size_t;
# define GIT_FORMAT_PRINTF(a,b) /* empty */
#endif
-/** Declare that a function's return value must be used. */
+/**
+ * Declare that a function's return value must be used.
+ *
+ * Used mostly to guard against potential silent bugs at runtime. This is
+ * recommended to be added to functions that:
+ *
+ * - Allocate / reallocate memory. This prevents memory leaks or errors where
+ * buffers are expected to have grown to a certain size, but could not be
+ * resized.
+ * - Acquire locks. When a lock cannot be acquired, that will almost certainly
+ * cause a data race / undefined behavior.
+ */
#if defined(__GNUC__)
# define GIT_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else