You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/05/07 05:36:49 UTC

[incubator-nuttx-apps] 02/02: apps/nshlib: fix unreachable code about i++

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

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

commit 1444e0dc768805de799035e93a590a05b1b5c593
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Sat May 7 11:54:02 2022 +0800

    apps/nshlib: fix unreachable code about i++
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 nshlib/nsh_session.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/nshlib/nsh_session.c b/nshlib/nsh_session.c
index 4286bcb15..8eb7fe360 100644
--- a/nshlib/nsh_session.c
+++ b/nshlib/nsh_session.c
@@ -70,7 +70,6 @@ int nsh_session(FAR struct console_stdio_s *pstate,
 {
   FAR struct nsh_vtbl_s *vtbl;
   int ret = EXIT_FAILURE;
-  int i;
 
   DEBUGASSERT(pstate);
   vtbl = &pstate->cn_vtbl;
@@ -116,21 +115,21 @@ int nsh_session(FAR struct console_stdio_s *pstate,
 
   /* Process the command line option */
 
-  for (i = 1; i < argc; i++)
+  if (argc > 1)
     {
-      if (strcmp(argv[i], "-h") == 0)
+      if (strcmp(argv[1], "-h") == 0)
         {
           nsh_output(vtbl, "Usage: %s [<script-path>|-c <command>]\n",
                      argv[0]);
           return EXIT_SUCCESS;
         }
-      else if (strcmp(argv[i], "-c") == 0)
+      else if (strcmp(argv[1], "-c") == 0)
         {
           /* Process the inline command */
 
-          if (i + 1 < argc)
+          if (argc > 2)
             {
-              return nsh_parse(vtbl, argv[i + 1]);
+              return nsh_parse(vtbl, argv[2]);
             }
           else
             {
@@ -138,26 +137,23 @@ int nsh_session(FAR struct console_stdio_s *pstate,
               return EXIT_FAILURE;
             }
         }
-      else if (argv[i][0] != '-')
+      else if (argv[1][0] == '-')
         {
-          break;
-        }
-
-      /* Unknown option */
-
-      nsh_error(vtbl, g_fmtsyntax, argv[0]);
-      return EXIT_FAILURE;
-    }
+          /* Unknown option */
 
-  if (i < argc)
-    {
+          nsh_error(vtbl, g_fmtsyntax, argv[0]);
+          return EXIT_FAILURE;
+        }
+      else
+        {
 #ifndef CONFIG_NSH_DISABLESCRIPT
-      /* Execute the shell script */
+          /* Execute the shell script */
 
-      return nsh_script(vtbl, argv[0], argv[i]);
+          return nsh_script(vtbl, argv[0], argv[1]);
 #else
-      return EXIT_FAILURE;
+          return EXIT_FAILURE;
 #endif
+        }
     }
 
   /* Then enter the command line parsing loop */