aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2026-08-01 03:34:37 +0000
committerKyle Evans <kevans@FreeBSD.org>2026-08-01 03:34:37 +0000
commit28327c58ee6de7ddbdcf0e56352b257d37f2103d (patch)
tree03f1184bd7bc43a6e05a31ae673cf489bbc20450
parentcecb0f45cb83349c60514da38fddce83ad042468 (diff)
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. Differential Revision: https://reviews.freebsd.org/D57353
-rw-r--r--lib/libc/stdio/open_memstream.c17
-rw-r--r--lib/libc/stdio/open_wmemstream.c16
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);
}