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-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 46f90316f nshlib/nsh_dbgcmds: set all of struct dbgmem_s in mem_parse()
46f90316f is described below
commit 46f90316f34653f0e6332b8cf05beb9d7c69d230
Author: huojianchao <[email protected]>
AuthorDate: Mon Nov 30 14:32:00 2026 +0800
nshlib/nsh_dbgcmds: set all of struct dbgmem_s in mem_parse()
mem_parse() left dm_write and dm_value unset when it returned -EINVAL.
The callers use the structure only when mem_parse() returns 0, but GCC
cannot always see that: with the PGO instrumentation options it reports
nsh_dbgcmds.c: error: 'mem.dm_value' may be used uninitialized
[-Werror=maybe-uninitialized]
for cmd_mw() on qemu-armv8a:nsh_smp. Clear the whole structure first.
No functional change.
Assisted-by: Kiro:claude-opus-5-5
Signed-off-by: huojianchao <[email protected]>
---
nshlib/nsh_dbgcmds.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/nshlib/nsh_dbgcmds.c b/nshlib/nsh_dbgcmds.c
index 8f2f0e215..a4fca77b9 100644
--- a/nshlib/nsh_dbgcmds.c
+++ b/nshlib/nsh_dbgcmds.c
@@ -80,6 +80,12 @@ static int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc,
FAR char **argv,
FAR char *pcvalue = strchr(argv[1], '=');
unsigned long lvalue = 0;
+ /* Set every field before any return, so that the callers never see an
+ * uninitialized one.
+ */
+
+ memset(mem, 0, sizeof(*mem));
+
/* Check if we are writing a value */
if (pcvalue)
@@ -96,11 +102,6 @@ static int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc,
FAR char **argv,
mem->dm_write = true;
mem->dm_value = (uint32_t)lvalue;
}
- else
- {
- mem->dm_write = false;
- mem->dm_value = 0;
- }
/* Get the address to be accessed */