commit 8fd5473a2572c7ac39459f5059f1cc8bdc32d59c
parent 8b68e39ca627bf0bbb3432beed0143e088af4307
Author: Rolf Eike Beer <eike@sf-mail.de>
Date: Fri, 8 May 2020 21:26:43 +0200
genalloc: unfold tail code
This was doing 2 assignments, a function call and a return on the same line.
This had the additional slight bug that if the allocation failed it returned 0,
but the allocation length in the struct passed in was already changed to the new
value. This would not do any harm on subsequent calls as the pointer was still
NULL and only that is checked.
Diffstat:
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/gen_allocdefs.h b/gen_allocdefs.h
@@ -15,7 +15,11 @@ static int ta_rplus ## _internal (ta *x, unsigned int n, unsigned int pluslen) \
x->a = nnum; \
return 1; } \
x->len = 0; \
- return !!(x->field = (type *) alloc((x->a = n) * sizeof(type))); } \
+ x->field = (type *) alloc(n * sizeof(type)); \
+ if (!x->field) \
+ return 0; \
+ x->a = n; \
+ return 1; } \
int ta_rplus(ta *x, unsigned int n) \
{ return ta_rplus ## _internal (x, n, x->len); }