summaryrefslogtreecommitdiff
path: root/src/libstddjb/alloc_realloc.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-04-29 19:08:19 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-04-29 19:08:19 +0000
commit038082c425c40037a28111934dfb5037edbcad8c (patch)
tree33a5af0aabf64334b93eb0c60158954dc2baf415 /src/libstddjb/alloc_realloc.c
parent20568ed2f00772e0a927ed21b7aa437c92ab8707 (diff)
downloadskalibs-038082c425c40037a28111934dfb5037edbcad8c.tar.xz
Fix alloc_realloc UB
void ** does not exist: the address of a generic pointer is not properly defined (different pointer types may have different representations). So, alloc_realloc cannot exist as is without UB. Fortunately, it's not supposed to be used in the skalibs programming style, and skalibs itself only uses it in two places (stralloc_ready_tuned and stralloc_shrink) where the pointer is a char *. So we just fix the UB by making alloc_realloc() take a char **, and it's only defined for that pointer type. Nothing to see here folks, nothing happened at all.
Diffstat (limited to 'src/libstddjb/alloc_realloc.c')
-rw-r--r--src/libstddjb/alloc_realloc.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libstddjb/alloc_realloc.c b/src/libstddjb/alloc_realloc.c
index 8787291..82be92b 100644
--- a/src/libstddjb/alloc_realloc.c
+++ b/src/libstddjb/alloc_realloc.c
@@ -3,9 +3,9 @@
#include <stdlib.h>
#include <skalibs/alloc.h>
-int alloc_realloc (void **x, size_t n)
+int alloc_realloc (char **x, size_t n)
{
- void *y = n ? realloc(*x, n) : (free(*x), alloc(0)) ;
+ char *y = n ? (char *)realloc(*x, n) : (free(*x), (char *)alloc(0)) ;
if (!y) return 0 ;
*x = y ;
return 1 ;