Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250423130705.1083910-1-kcxt@postmarketos.org>
Date: Wed, 23 Apr 2025 15:06:48 +0200
From: Casey Connolly <kcxt@...tmarketos.org>
To: musl@...ts.openwall.com
Cc: Casey Connolly <kcxt@...tmarketos.org>
Subject: [PATCH v2] stdio: skip empty iovec when buffering is disabled

When buffering on a FILE is disabled we still send both iovecs, even
though the first one is always empty. Clean things up by skipping the
empty iovec instead.
---

Changes since v1:
- reword to better reflect the change
- V1: https://www.openwall.com/lists/musl/2025/04/23/1

---
 src/stdio/__stdio_write.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/stdio/__stdio_write.c b/src/stdio/__stdio_write.c
index d2d89475b0f9..b08913266269 100644
--- a/src/stdio/__stdio_write.c
+++ b/src/stdio/__stdio_write.c
@@ -9,8 +9,13 @@ size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
 	};
 	struct iovec *iov = iovs;
 	size_t rem = iov[0].iov_len + iov[1].iov_len;
 	int iovcnt = 2;
+
+	if (!iov->iov_len) {
+		iov++;
+		iovcnt--;
+	}
 	ssize_t cnt;
 	for (;;) {
 		cnt = syscall(SYS_writev, f->fd, iov, iovcnt);
 		if (cnt == rem) {
-- 
2.49.0

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.