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

commit 325c5036b962044e5ae38854b08b7fb10ff21ec4
Author: huojianchao <[email protected]>
AuthorDate: Wed Oct 14 11:49:38 2026 +0800

    drivers/syslog: check the CRLF write result
    
    The result of the CR/LF write in syslog_write_foreach() was never used,
    so a channel filling up between the payload write and the CR/LF write
    had its failure discarded while nwritten still claimed the '\n' was
    consumed.
    
    Account the '\n' only when its CR/LF expansion was stored.  nwritten
    cannot be rewound, the bytes before head are already out, so the '\n'
    is left to the tail write, which emits it without the CR.
    
    Signed-off-by: huojianchao <[email protected]>
---
 drivers/syslog/syslog_write.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/syslog/syslog_write.c b/drivers/syslog/syslog_write.c
index 33f597c46c0..e45376158b9 100644
--- a/drivers/syslog/syslog_write.c
+++ b/drivers/syslog/syslog_write.c
@@ -193,8 +193,12 @@ ssize_t syslog_write_foreach(int priority, FAR const char 
*buffer,
                       continue;
                     }
 
+                  /* On failure leave the '\n' to the tail write: rewinding
+                   * would duplicate the bytes already written.
+                   */
+
                   ret = write(channel, "\r\n", 2);
-                  nwritten = head + 1;
+                  nwritten = ret > 0 ? head + 1 : head;
                 }
             }
 #endif

Reply via email to