summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-05-13 22:08:45 +0200
committerLouis Burda <quent.burda@gmail.com>2023-05-13 22:12:19 +0200
commit20a203a200b26069fc1bbd7d276014b01bd884c0 (patch)
tree4e86b03dfcb229727eb7babfc5bde72e930c3529
parent9fe89a48bb89dc6740787c9ed8c95b5339bba905 (diff)
downloadlibstrvec-c-20a203a200b26069fc1bbd7d276014b01bd884c0.tar.gz
libstrvec-c-20a203a200b26069fc1bbd7d276014b01bd884c0.zip
Ensure allocator return codes are properly negated
-rw-r--r--src/strvec.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/strvec.c b/src/strvec.c
index dbc964e..13699a3 100644
--- a/src/strvec.c
+++ b/src/strvec.c
@@ -47,10 +47,14 @@ strvec_alloc(size_t cap, struct allocator *allocator, int *_rc)
rc = _rc ? _rc : &stub;
strvec = allocator->alloc(sizeof(struct strvec), rc);
+ if (!strvec && _rc) *rc = -*rc;
if (!strvec) return NULL;
*rc = strvec_init(strvec, cap, allocator);
- if (*rc) return NULL;
+ if (*rc) {
+ allocator->free(strvec);
+ return NULL;
+ }
return strvec;
}
@@ -71,8 +75,9 @@ strvec_free(struct strvec *strvec)
rc = allocator->free(strvec);
LIBSTRVEC_ABORT_ON_ALLOC(rc);
+ if (rc) return -rc;
- return rc;
+ return 0;
}
int