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

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

commit 033b6c8d01e8cc7e686ab2b4e119075d1f158a24
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Oct 6 18:34:40 2026 +0200

    examples/nxflat: Fix the stack size and the argv[0] check of the task test.
    
    The child task had a 512 byte stack.  Its first printf() overflows it and
    overwrites the argument strings at the bottom of the stack, so the child
    saw an empty argv[0].  Use CONFIG_DEFAULT_TASK_STACKSIZE.
    
    With CONFIG_TASK_NAME_SIZE set to 0 the test expected argv[0] to be
    "<noname>".  But argv[0] is always the name given to task_create(); the
    option only limits the copy in the TCB.  Compare with that name in all
    configurations.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 examples/nxflat/tests/task/task.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/examples/nxflat/tests/task/task.c 
b/examples/nxflat/tests/task/task.c
index 8a208d5aa..82f9d3909 100644
--- a/examples/nxflat/tests/task/task.c
+++ b/examples/nxflat/tests/task/task.c
@@ -41,10 +41,6 @@ static char child_name[] = "child";
 static char child_arg[] = "Hello from your parent!";
 static sem_t g_sem;
 
-#if CONFIG_TASK_NAME_SIZE == 0
-static char no_name[] = "<noname>";
-#endif
-
 /****************************************************************************
  * Privite Functions
  ****************************************************************************/
@@ -68,21 +64,14 @@ int child_task(int argc, char **argv)
     }
   printf("Child: argv[0]=\"%s\"\n", argv[0]);
 
-#if CONFIG_TASK_NAME_SIZE == 0
-  if (strcmp(argv[0], no_name) != 0)
-    {
-      printf("Child: expected argv[0] to be \"%s\"\n", no_name);
-      printf("Child: Exit-ting with status=3\n");
-      exit(3);
-    }
-#else
-  if (strncmp(argv[0], child_name, CONFIG_TASK_NAME_SIZE) != 0)
+  /* argv[0] is the name given to task_create(), whatever the TCB keeps */
+
+  if (strcmp(argv[0], child_name) != 0)
     {
       printf("Child: expected argv[0] to be \"%s\"\n", child_name);
       printf("Child: Exit-ting with status=3\n");
       exit(3);
     }
-#endif
 
   printf("Child: argv[1]=\"%s\"\n", argv[1]);
 
@@ -116,7 +105,10 @@ int main(int argc, char **argv)
 
   child_argv[0] = child_arg;
   child_argv[1] = 0;
-  child_pid = task_create(child_name, 50, 512,
+
+  /* printf() alone overflows a 512 byte stack and overwrites argv */
+
+  child_pid = task_create(child_name, 50, CONFIG_DEFAULT_TASK_STACKSIZE,
                           child_task, (FAR char * const *)child_argv);
   if (child_pid < 0)
     {

Reply via email to