From: claudio Date: Wed, 21 Jun 2023 13:11:49 +0000 (+0000) Subject: Use recallocarray() consistently. recallocarray() was introduced to simplify X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=edc829431effa915c16b067b5da3c6ab86b7fbca;p=openbsd Use recallocarray() consistently. recallocarray() was introduced to simplify 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@ --- diff --git a/lib/libc/stdio/open_memstream.c b/lib/libc/stdio/open_memstream.c index 6ee5a5c2794..7b063e37454 100644 --- a/lib/libc/stdio/open_memstream.c +++ b/lib/libc/stdio/open_memstream.c @@ -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 @@ -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; } diff --git a/lib/libc/stdio/open_wmemstream.c b/lib/libc/stdio/open_wmemstream.c index aceef35153c..01dd782768d 100644 --- a/lib/libc/stdio/open_wmemstream.c +++ b/lib/libc/stdio/open_wmemstream.c @@ -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 @@ -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; }