The branch main has been updated by kevans:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=28327c58ee6de7ddbdcf0e56352b257d37f2103d

commit 28327c58ee6de7ddbdcf0e56352b257d37f2103d
Author:     Kyle Evans <[email protected]>
AuthorDate: 2026-08-01 03:34:37 +0000
Commit:     Kyle Evans <[email protected]>
CommitDate: 2026-08-01 03:34:37 +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.
    Differential Revision:  https://reviews.freebsd.org/D57353
---
 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);
 }

Reply via email to