This is an automated email from the ASF dual-hosted git repository.

simbit18 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 14fb39a6cdc sched/misc: fix incomplete data emission in coredump 
elf_emit function
14fb39a6cdc is described below

commit 14fb39a6cdc799d627e24938ef4262ffc7039df0
Author: chenzhaoxiang <[email protected]>
AuthorDate: Thu Feb 26 17:18:08 2026 +0800

    sched/misc: fix incomplete data emission in coredump elf_emit function
    
    The elf_emit() function in coredump.c was only checking for negative 
returnvalues
    from lib_stream_puts() to detect write failures. However, 
lib_stream_puts()can return 0
    to indicate that no bytes were written (e.g., due to stream 
full,end-of-file, or other
    non-error conditions that prevent data writing).
    
    This oversight meant that cases where lib_stream_puts() returned 0 would 
bypassthe error handling,
    leading to incomplete data emission in the core dump withoutany failure 
indication.
    The loop would continue attempting to write the remainingdata, resulting in 
partial or corrupted core dump files.
    
    This fix modifies the condition from ret < 0 to ret <= 0 to:
    
    1. Catch both error conditions (negative return values) and zero-byte 
writes.
    2. Immediately break the write loop and propagate the failure, ensuring the 
core
       dump process correctly aborts when data cannot be written.
    
    This change improves the reliability of core dump generation by ensuring 
allfailed or
    incomplete write attempts are properly handled, preventing corruptedcore 
dump files.
    
    Signed-off-by: chao an <[email protected]>
---
 sched/misc/coredump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sched/misc/coredump.c b/sched/misc/coredump.c
index 204be9195c3..f4089a7dcc0 100644
--- a/sched/misc/coredump.c
+++ b/sched/misc/coredump.c
@@ -149,7 +149,7 @@ static int elf_emit(FAR struct elf_dumpinfo_s *cinfo,
   while (total > 0)
     {
       ret = lib_stream_puts(cinfo->stream, ptr, total);
-      if (ret < 0)
+      if (ret <= 0)
         {
           break;
         }

Reply via email to