You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2022/09/19 06:30:52 UTC

[mynewt-core] branch master updated: sys/log: Fix dangling pointer

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

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new ffa541e69 sys/log: Fix dangling pointer
ffa541e69 is described below

commit ffa541e698490bf5cc8ab58b3234764b5eff5b89
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Thu Sep 15 14:30:01 2022 +0200

    sys/log: Fix dangling pointer
    
    GCC 12 reports following error:
    
    Compiling repos/apache-mynewt-core/sys/log/full/src/log_level.c
    Error: repos/apache-mynewt-core/sys/log/full/src/log.c: In function
         'log_walk_body_section':
    repos/apache-mynewt-core/sys/log/full/src/log.c:923:24: error: storing
        the address of local variable 'lwba' in '*log_offset.lo_arg'
        [-Werror=dangling-pointer=]
      923 |     log_offset->lo_arg = &lwba;
          |     ~~~~~~~~~~~~~~~~~~~^~~~~~~
    repos/apache-mynewt-core/sys/log/full/src/log.c:917:30: note: 'lwba'
        declared here
      917 |     struct log_walk_body_arg lwba = {
          |                              ^~~~
    repos/apache-mynewt-core/sys/log/full/src/log.c:917:30: note:
        'log_offset' declared here
    cc1: all warnings being treated as errors
---
 sys/log/full/src/log.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index 577934f9b..4ef785ebf 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -920,13 +920,13 @@ log_walk_body_section(struct log *log, log_walk_body_func_t walk_body_func,
     };
     int rc;
 
-    log_offset->lo_arg = &lwba;
-
     if (!log->l_log->log_walk_sector) {
         rc = SYS_ENOTSUP;
         goto err;
     }
 
+    log_offset->lo_arg = &lwba;
+
     rc = log->l_log->log_walk_sector(log, log_walk_body_fn, log_offset);
     log_offset->lo_arg = lwba.arg;