anchao commented on code in PR #17455:
URL: https://github.com/apache/nuttx/pull/17455#discussion_r2601971639


##########
drivers/note/note_driver.c:
##########
@@ -2095,37 +2093,42 @@ void sched_note_filter_tag(FAR struct 
note_filter_named_tag_s *oldf,
  *
  * Input Parameters:
  *   PID - Task ID
+ *   buf - A writable buffer to hold the task name
+ *   len - The length of the buffer
  *
  * Returned Value:
- *   Return name if task name can be retrieved, otherwise NULL
+ *   None
+ *
  ****************************************************************************/
 
-FAR const char *note_get_taskname(pid_t pid)
+void note_get_taskname(pid_t pid, FAR char *buf, size_t len)
 {
-  FAR struct note_taskname_info_s *ti;
-  FAR struct tcb_s *tcb;
-  UNUSED(ti);
+#if CONFIG_TASK_NAME_SIZE > 0
+  FAR struct tcb_s *tcb = nxsched_get_tcb(pid);
 
-  tcb = nxsched_get_tcb(pid);
   if (tcb != NULL)
     {
-      return tcb->name;
+      strlcpy(buf, tcb->name, len);
+      return;
     }
 
-#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
-  ti = note_find_taskname(pid);
-  if (ti != NULL)
+#  if defined(CONFIG_SCHED_INSTRUMENTATION_SWITCH) && \
+      (CONFIG_DRIVERS_NOTE_TASKNAME_BUFSIZE > 0)
+  else
     {
-      return ti->name;
-    }
+      FAR struct note_taskname_info_s *ti = note_find_taskname(pid);
 
-  return NULL;
-#else
-  return "unknown";
+      if (ti != NULL)
+        {
+          strlcpy(buf, ti->name, len);
+          return;
+        }
+    }
+#  endif
 #endif
-}
 
-#endif
+  strlcpy(buf, "<noname>", len);

Review Comment:
   we could return the rodata in final case to avoid strlcpy



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to