You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/10/13 06:06:04 UTC

(nuttx) 08/13: fix build warning to [-Wstringop-overread].

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

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 4b318cb2cbe3deeef6051674b0aa55356f152dd4
Author: cuiziwei <cu...@xiaomi.com>
AuthorDate: Wed Jan 24 14:52:12 2024 +0800

    fix build warning to [-Wstringop-overread].
    
    note/note_driver.c:639:21: warning: 'strlen' reading 1 or more bytes from a region of size 0 [-Wstringop-overread]
      639 |           namelen = strlen(tcb->name);
          |                     ^~~~~~~~~~~~~~~~~
    
    Signed-off-by: cuiziwei <cu...@xiaomi.com>
---
 drivers/note/note_driver.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/note/note_driver.c b/drivers/note/note_driver.c
index 8221e04327..63d89b7d9b 100644
--- a/drivers/note/note_driver.c
+++ b/drivers/note/note_driver.c
@@ -642,7 +642,7 @@ void sched_note_start(FAR struct tcb_s *tcb)
   bool formatted = false;
 
 #if CONFIG_TASK_NAME_SIZE > 0
-  int namelen;
+  int namelen = 0;
 #endif
 
   for (driver = g_note_drivers; *driver; driver++)
@@ -671,7 +671,10 @@ void sched_note_start(FAR struct tcb_s *tcb)
            */
 
 #if CONFIG_TASK_NAME_SIZE > 0
-          namelen = strlen(tcb->name);
+          if (tcb->name[0] != '\0')
+            {
+              namelen = strlen(tcb->name);
+            }
 
           DEBUGASSERT(namelen <= CONFIG_TASK_NAME_SIZE);
           strlcpy(note.nsa_name, tcb->name, sizeof(note.nsa_name));