libstrvec-c

C string vector library
git clone https://git.sinitax.com/sinitax/libstrvec-c
Log | Files | Refs | LICENSE | sfeed.txt

commit 20a203a200b26069fc1bbd7d276014b01bd884c0
parent 9fe89a48bb89dc6740787c9ed8c95b5339bba905
Author: Louis Burda <quent.burda@gmail.com>
Date:   Sat, 13 May 2023 22:08:45 +0200

Ensure allocator return codes are properly negated

Diffstat:
Msrc/strvec.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git 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