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 <cuiziwei@xiaomi.com>
This commit is contained in:
cuiziwei 2024-01-24 14:52:12 +08:00 committed by Xiang Xiao
parent 04f3ff5942
commit 4b318cb2cb

View file

@ -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));