Use recallocarray() consistently. recallocarray() was introduced to simplify
authorclaudio <claudio@openbsd.org>
Wed, 21 Jun 2023 13:11:49 +0000 (13:11 +0000)
committerclaudio <claudio@openbsd.org>
Wed, 21 Jun 2023 13:11:49 +0000 (13:11 +0000)
exactly this use case where the new memory needs to be zeroed during resize.
Since recallocarray() takes care of all this there is no need to bzero()
memory anymore.

OK tb@ millert@

lib/libc/stdio/open_memstream.c
lib/libc/stdio/open_wmemstream.c

index 6ee5a5c..7b063e3 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: open_memstream.c,v 1.8 2019/05/02 08:30:10 yasuoka Exp $      */
+/*     $OpenBSD: open_memstream.c,v 1.9 2023/06/21 13:11:49 claudio Exp $      */
 
 /*
  * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org>
@@ -53,7 +53,6 @@ memstream_write(void *v, const char *b, int l)
                p = recallocarray(st->string, st->size, sz, 1);
                if (!p)
                        return (-1);
-               bzero(p + st->size, sz - st->size);
                *st->pbuf = st->string = p;
                st->size = sz;
        }
index aceef35..01dd782 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: open_wmemstream.c,v 1.8 2015/09/12 16:23:14 guenther Exp $    */
+/*     $OpenBSD: open_wmemstream.c,v 1.9 2023/06/21 13:11:49 claudio Exp $     */
 
 /*
  * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org>
@@ -52,10 +52,9 @@ wmemstream_write(void *v, const char *b, int l)
 
                if (sz < end + 1)
                        sz = end + 1;
-               p = reallocarray(st->string, sz, sizeof(wchar_t));
+               p = recallocarray(st->string, st->size, sz, sizeof(wchar_t));
                if (!p)
                        return (-1);
-               bzero(p + st->size, (sz - st->size) * sizeof(wchar_t));
                *st->pbuf = st->string = p;
                st->size = sz;
        }