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/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new ea11446  sched/task/task_spawn.c: initialize variables explicitly
ea11446 is described below

commit ea1144630dcc173e39d1df1fc11ba5a238b3c855
Author: Juha Niskanen <juha.niska...@haltian.com>
AuthorDate: Mon Jun 7 15:21:19 2021 +0300

    sched/task/task_spawn.c: initialize variables explicitly
    
    'pid' cannot really be used uninitialized, but Clang analyzer does not
    see it.  Add initializer to silence it and also make debugging slightly
    easier.
    
    Explicitly set pid's address to NULL to fix this complaint:
    
      "Address of stack memory associated with local variable 'pid' is still
       referred to by the global variable 'g_spawn_parms' upon returning to
       the caller."
    
    No functional change.
    
    Signed-off-by: Juha Niskanen <juha.niska...@haltian.com>
---
 sched/task/task_spawn.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sched/task/task_spawn.c b/sched/task/task_spawn.c
index 8c974c0..d5740c1 100644
--- a/sched/task/task_spawn.c
+++ b/sched/task/task_spawn.c
@@ -312,7 +312,7 @@ int task_spawn(FAR const char *name, main_t entry,
 {
   struct sched_param param;
   pid_t proxy;
-  pid_t pid;
+  pid_t pid = INVALID_PROCESS_ID;
 #ifdef CONFIG_SCHED_WAITPID
   int status;
 #endif
@@ -374,6 +374,7 @@ int task_spawn(FAR const char *name, main_t entry,
   if (ret < 0)
     {
       serr("ERROR: nxsched_get_param failed: %d\n", ret);
+      g_spawn_parms.pid = NULL;
       spawn_semgive(&g_spawn_parmsem);
       return ret;
     }
@@ -442,6 +443,7 @@ errout_with_lock:
 #ifdef CONFIG_SCHED_WAITPID
   sched_unlock();
 #endif
+  g_spawn_parms.pid = NULL;
   spawn_semgive(&g_spawn_parmsem);
   return ret;
 }

Reply via email to