This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new d2e9244c1b8 libs/libc/stream: fix size_t swallowing negative errno in
bufferedoutstream_puts
d2e9244c1b8 is described below
commit d2e9244c1b8d2688bb40095b2a27edcf666b7a96
Author: fangxinyong <[email protected]>
AuthorDate: Mon Jun 1 23:07:04 2026 +0800
libs/libc/stream: fix size_t swallowing negative errno in
bufferedoutstream_puts
bufferedoutstream_puts() declared its return holder as size_t and assigned
the int result of lib_stream_flush() to it. Since lib_stream_flush() may return
a negative errno, the subsequent `if (ret >= 0)` check is always true for an
unsigned type, so a flush failure was silently swallowed and the function
reported a bogus huge byte count via its ssize_t return.
Change the holder to ssize_t so the negative-errno check works correctly.
Fixes MISRA C:2012 Rule 14.3 (invariant controlling expression) flagged by
Coverity ASIL-D scan.
Signed-off-by: fangxinyong <[email protected]>
---
libs/libc/stream/lib_bufferedoutstream.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/libc/stream/lib_bufferedoutstream.c
b/libs/libc/stream/lib_bufferedoutstream.c
index 25b54908415..1b6c28133eb 100644
--- a/libs/libc/stream/lib_bufferedoutstream.c
+++ b/libs/libc/stream/lib_bufferedoutstream.c
@@ -68,7 +68,7 @@ static ssize_t bufferedoutstream_puts(FAR struct
lib_outstream_s *self,
{
FAR struct lib_bufferedoutstream_s *stream =
(FAR struct lib_bufferedoutstream_s *)self;
- size_t ret = len;
+ ssize_t ret = len;
if (stream->pending + len <= CONFIG_STREAM_OUT_BUFFER_SIZE)
{