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

vipulrahane pushed a commit to branch vipul/log_trailer_fix
in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git

commit 390a1fa1d0e8d251f7996632bef03c988cc5e32f
Author: Vipul Rahane <[email protected]>
AuthorDate: Fri Jul 25 12:59:09 2025 -0700

    cmd/log_mgmt: Subtract trailer length on log read
    
    - trailer_length and size of the trailer should be subtracted
      from the log entry being read to get only the log entry data
---
 cmd/log_mgmt/port/mynewt/src/mynewt_log_mgmt.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/cmd/log_mgmt/port/mynewt/src/mynewt_log_mgmt.c 
b/cmd/log_mgmt/port/mynewt/src/mynewt_log_mgmt.c
index 8f7e50f..7bd6bf4 100644
--- a/cmd/log_mgmt/port/mynewt/src/mynewt_log_mgmt.c
+++ b/cmd/log_mgmt/port/mynewt/src/mynewt_log_mgmt.c
@@ -161,6 +161,7 @@ mynewt_log_mgmt_walk_cb(struct log *log, struct log_offset 
*log_offset,
 {
     struct mynewt_log_mgmt_walk_arg *mynewt_log_mgmt_walk_arg;
     struct log_mgmt_entry entry;
+    uint16_t trailer_len = 0;
     int read_len;
     int offset;
     int rc;
@@ -199,6 +200,16 @@ mynewt_log_mgmt_walk_cb(struct log *log, struct log_offset 
*log_offset,
     entry.len = len;
     entry.data = mynewt_log_mgmt_walk_arg->chunk;
 
+#if MYNEWT_VAL(LOG_FLAGS_TRAILER)
+    trailer_len -= log_read_trailer_len(log, dptr);
+    if (trailer_len) {
+        /* If trailer is present, so is the length of the trailer */
+        trailer_len += LOG_TRAILER_LEN_SIZE;
+    }
+
+    len -= trailer_len;
+#endif
+
     for (offset = 0; offset < len; offset += LOG_MGMT_CHUNK_LEN) {
         if (len - offset < LOG_MGMT_CHUNK_LEN) {
             read_len = len - offset;

Reply via email to