aboutsummaryrefslogtreecommitdiff
path: root/mime.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-01-21 16:14:01 +0000
committerOmar Polo <op@omarpolo.com>2021-01-21 16:14:01 +0000
commit95210bb3961727e034b99912a65700f6ace49753 (patch)
tree1ec42688d7a6f9598d3a2605bf1602d22f5be3b5 /mime.c
parenta5a09e44b2ca3fa86ecf401f3907dff8c2012d98 (diff)
use recallocarray
it also does an overflow check on multiplication, other than being more readable.
Diffstat (limited to 'mime.c')
-rw-r--r--mime.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/mime.c b/mime.c
index f389aa8..81bc2ef 100644
--- a/mime.c
+++ b/mime.c
@@ -35,11 +35,15 @@ init_mime(struct mime *mime)
void
add_mime(struct mime *mime, const char *mt, const char *ext)
{
+ size_t oldcap;
+
if (mime->len == mime->cap) {
+ oldcap = mime->cap;
mime->cap *= 1.5;
- mime->t = realloc(mime->t, mime->cap * sizeof(struct etm));
+ mime->t = recallocarray(mime->t, oldcap, mime->cap,
+ sizeof(struct etm));
if (mime->t == NULL)
- fatal("realloc: %s", strerror(errno));
+ err(1, "recallocarray");
}
mime->t[mime->len].mime = mt;