git: c675e0710ea6 - stable/15 - stdio: *memstream: slightly streamline growth function
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 07 Aug 2026 01:48:18 UTC
The branch stable/15 has been updated by kevans:
URL: https://cgit.FreeBSD.org/src/commit/?id=c675e0710ea6c3f8608fcb356ea49ae81e0aefd8
commit c675e0710ea6c3f8608fcb356ea49ae81e0aefd8
Author: Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2026-08-01 03:34:37 +0000
Commit: Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2026-08-06 23:37:17 +0000
stdio: *memstream: slightly streamline growth function
Inverting the condition after realloc*() is a minor cleanup, but makes
the success path a little cleaner to ease a future change.
Reviewed by: des, jhb
Sponsored by: Klara, Inc.
(cherry picked from commit 28327c58ee6de7ddbdcf0e56352b257d37f2103d)
---
lib/libc/stdio/open_memstream.c | 17 ++++++++---------
lib/libc/stdio/open_wmemstream.c | 16 +++++++---------
2 files changed, 15 insertions(+), 18 deletions(-)
diff --git a/lib/libc/stdio/open_memstream.c b/lib/libc/stdio/open_memstream.c
index 371022adf6b3..29de688376bf 100644
--- a/lib/libc/stdio/open_memstream.c
+++ b/lib/libc/stdio/open_memstream.c
@@ -62,17 +62,16 @@ memstream_grow(struct memstream *ms, fpos_t newoff)
newsize = newoff;
if (newsize > ms->len) {
buf = realloc(*ms->bufp, newsize + 1);
- if (buf != NULL) {
+ if (buf == NULL)
+ return (0);
+
#ifdef DEBUG
- fprintf(stderr, "MS: %p growing from %zd to %zd\n",
- ms, ms->len, newsize);
+ fprintf(stderr, "MS: %p growing from %zd to %zd\n",
+ ms, ms->len, newsize);
#endif
- memset(buf + ms->len + 1, 0, newsize - ms->len);
- *ms->bufp = buf;
- ms->len = newsize;
- return (1);
- }
- return (0);
+ memset(buf + ms->len + 1, 0, newsize - ms->len);
+ *ms->bufp = buf;
+ ms->len = newsize;
}
return (1);
}
diff --git a/lib/libc/stdio/open_wmemstream.c b/lib/libc/stdio/open_wmemstream.c
index 213d61fcd4dd..0bed4cff5d11 100644
--- a/lib/libc/stdio/open_wmemstream.c
+++ b/lib/libc/stdio/open_wmemstream.c
@@ -63,17 +63,15 @@ wmemstream_grow(struct wmemstream *ms, fpos_t newoff)
newsize = newoff;
if (newsize > ms->len) {
buf = reallocarray(*ms->bufp, newsize + 1, sizeof(wchar_t));
- if (buf != NULL) {
+ if (buf == NULL)
+ return (0);
#ifdef DEBUG
- fprintf(stderr, "WMS: %p growing from %zd to %zd\n",
- ms, ms->len, newsize);
+ fprintf(stderr, "WMS: %p growing from %zd to %zd\n",
+ ms, ms->len, newsize);
#endif
- wmemset(buf + ms->len + 1, 0, newsize - ms->len);
- *ms->bufp = buf;
- ms->len = newsize;
- return (1);
- }
- return (0);
+ wmemset(buf + ms->len + 1, 0, newsize - ms->len);
+ *ms->bufp = buf;
+ ms->len = newsize;
}
return (1);
}