mirror of
https://git.proxmox.com/git/libgit2
synced 2026-01-06 22:58:58 +00:00
common: introduce GITERR_CHECK_ALLOC_BUF
We commonly have to check if a git_buf has been allocated correctly or if we ran out of memory. Introduce a new macro similar to `GITERR_CHECK_ALLOC` which checks if we ran OOM and if so returns an error. Provide a `#nodef` for Coverity to mark the error case as an abort path.
This commit is contained in:
parent
f2a554b45e
commit
859ed5ddc7
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#nodef GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { __coverity_panic__(); }
|
||||
#nodef GITERR_CHECK_ALLOC_BUF(buf) if (buf == NULL || git_buf_oom(buf)) { __coverity_panic__(); }
|
||||
|
||||
#nodef GITERR_CHECK_ALLOC_ADD(out, one, two) \
|
||||
if (GIT_ADD_SIZET_OVERFLOW(out, one, two)) { __coverity_panic__(); }
|
||||
|
||||
@ -89,6 +89,11 @@
|
||||
*/
|
||||
#define GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; }
|
||||
|
||||
/**
|
||||
* Check a buffer allocation result, returning -1 if it failed.
|
||||
*/
|
||||
#define GITERR_CHECK_ALLOC_BUF(buf) if ((void *)(buf) == NULL || git_buf_oom(buf)) { return -1; }
|
||||
|
||||
/**
|
||||
* Check a return value and propagate result if non-zero.
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user