summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-05-20 23:00:43 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-05-20 23:00:43 +0000
commit2518eebc8b79441328b512dd90d554be1fb93f8d (patch)
tree7a0355849e3b951f08820be42036dd39575cf322
parentc1268665ba75e51fc2d7057c543155b1745875e3 (diff)
downloadmandoc-2518eebc8b79441328b512dd90d554be1fb93f8d.tar.gz
fix integer overflows by using reallocarray(3)
-rw-r--r--compat_stringlist.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/compat_stringlist.c b/compat_stringlist.c
index 1068b461..42923baf 100644
--- a/compat_stringlist.c
+++ b/compat_stringlist.c
@@ -48,7 +48,7 @@ sl_init(void)
sl->sl_cur = 0;
sl->sl_max = _SL_CHUNKSIZE;
- sl->sl_str = malloc(sl->sl_max * sizeof(char *));
+ sl->sl_str = reallocarray(NULL, sl->sl_max, sizeof(char *));
if (sl->sl_str == NULL)
err(1, "stringlist");
return sl;
@@ -63,7 +63,8 @@ sl_add(StringList *sl, char *name)
{
if (sl->sl_cur == sl->sl_max - 1) {
sl->sl_max += _SL_CHUNKSIZE;
- sl->sl_str = reallocf(sl->sl_str, sl->sl_max * sizeof(char *));
+ sl->sl_str = reallocarray(sl->sl_str,
+ sl->sl_max, sizeof(char *));
if (sl->sl_str == NULL)
return (-1);
}