diff options
| author | lhchavez <lhchavez@lhchavez.com> | 2021-07-30 06:34:15 -0700 |
|---|---|---|
| committer | lhchavez <lhchavez@lhchavez.com> | 2021-08-08 19:08:59 -0700 |
| commit | 4e8376a98cedf82f9e5f5e1acbabba031ed7130c (patch) | |
| tree | 12ea89f1292007a5d88489b487dbb38c63678826 /src/common.h | |
| parent | c4cbab3201a1b5e75f6ef28e724956a36cb66dc0 (diff) | |
| download | libgit2-4e8376a98cedf82f9e5f5e1acbabba031ed7130c.tar.gz | |
Move GIT_WARN_UNUSED_RESULT from the public to the private API
Diffstat (limited to 'src/common.h')
| -rw-r--r-- | src/common.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/common.h b/src/common.h index f83eeb69e..a7c6e8e29 100644 --- a/src/common.h +++ b/src/common.h @@ -136,6 +136,24 @@ GIT_INLINE(int) git_error__check_version(const void *structure, unsigned int exp #define GIT_ERROR_CHECK_VERSION(S,V,N) if (git_error__check_version(S,V,N) < 0) return -1 /** + * 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 +# define GIT_WARN_UNUSED_RESULT +#endif + +/** * Initialize a structure with a version. */ GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int version) |
