fix segfault on parsing of -v and -m

The length is initially 0 so it needs to be incremented before
reallocarray to avoid ...alloc(0); and keep some space for the element
to insert.
This commit is contained in:
Josuah Demangeon 2018-04-02 02:54:59 +02:00 committed by Laslo Hunhold
parent 6770dc06e6
commit 69bb7710eb

4
main.c
View file

@ -166,7 +166,7 @@ main(int argc, char *argv[])
if (!(tok = strdup(EARGF(usage())))) { if (!(tok = strdup(EARGF(usage())))) {
die("strdup:"); die("strdup:");
} }
if (!(s.vhost = reallocarray(s.vhost, s.vhost_len++, if (!(s.vhost = reallocarray(s.vhost, ++s.vhost_len,
sizeof(struct vhost)))) { sizeof(struct vhost)))) {
die("reallocarray:"); die("reallocarray:");
} }
@ -182,7 +182,7 @@ main(int argc, char *argv[])
if (!(tok = strdup(EARGF(usage())))) { if (!(tok = strdup(EARGF(usage())))) {
die("strdup:"); die("strdup:");
} }
if (!(s.map = reallocarray(s.map, s.map_len++, if (!(s.map = reallocarray(s.map, ++s.map_len,
sizeof(struct map)))) { sizeof(struct map)))) {
die("reallocarray:"); die("reallocarray:");
} }