You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/03/29 14:47:15 UTC

[incubator-nuttx-apps] branch master updated: quickjs: fix compile warning

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-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new cd1bc19  quickjs: fix compile warning
cd1bc19 is described below

commit cd1bc19bf98c601c2c9b74aaabca42421be2d698
Author: yinshengkai <yi...@xiaomi.com>
AuthorDate: Sat Mar 19 17:21:47 2022 +0800

    quickjs: fix compile warning
    
    optind is a global variable in getopt.h (a macro defined in stdlib.h in nuttx).
    Here it is used as a variable, not a variable of getopt
---
 interpreters/quickjs/qjsmini.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/interpreters/quickjs/qjsmini.c b/interpreters/quickjs/qjsmini.c
index 45f8546..6979e95 100644
--- a/interpreters/quickjs/qjsmini.c
+++ b/interpreters/quickjs/qjsmini.c
@@ -390,7 +390,8 @@ uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename)
 static int js_eval_file(JSContext *ctx, const char *filename, int module)
 {
   uint8_t *buf;
-  int ret, eval_flags;
+  int ret;
+  int eval_flags;
   size_t buf_len;
 
   buf = js_load_file(ctx, &buf_len, filename);
@@ -482,7 +483,7 @@ int main(int argc, char *argv[])
       malloc_usable_size,
   };
 
-  int optind;
+  int argi;
   char *expr = NULL;
   int dump_memory = 0;
   int trace_memory = 0;
@@ -490,15 +491,15 @@ int main(int argc, char *argv[])
   size_t memory_limit = 0;
   size_t stack_size = 0;
 
-  optind = 1;
-  while (optind < argc && *argv[optind] == '-')
+  argi = 1;
+  while (argi < argc && *argv[argi] == '-')
     {
-      char *arg = argv[optind] + 1;
+      char *arg = argv[argi] + 1;
       const char *longopt = "";
 
       if (!*arg)
         break;
-      optind++;
+      argi++;
       if (*arg == '-')
         {
           longopt = arg + 1;
@@ -529,9 +530,9 @@ int main(int argc, char *argv[])
                   break;
                 }
 
-              if (optind < argc)
+              if (argi < argc)
                 {
-                  expr = argv[optind++];
+                  expr = argv[argi++];
                   break;
                 }
 
@@ -559,25 +560,25 @@ int main(int argc, char *argv[])
 
           if (!strcmp(longopt, "memory-limit"))
             {
-              if (optind >= argc)
+              if (argi >= argc)
                 {
                   fprintf(stderr, "expecting memory limit");
                   exit(1);
                 }
 
-              memory_limit = (size_t)strtod(argv[optind++], NULL);
+              memory_limit = (size_t)strtod(argv[argi++], NULL);
               continue;
             }
 
           if (!strcmp(longopt, "stack-size"))
             {
-              if (optind >= argc)
+              if (argi >= argc)
                 {
                   fprintf(stderr, "expecting stack size");
                   exit(1);
                 }
 
-              stack_size = (size_t)strtod(argv[optind++], NULL);
+              stack_size = (size_t)strtod(argv[argi++], NULL);
               continue;
             }
 
@@ -642,10 +643,10 @@ int main(int argc, char *argv[])
               goto fail;
             }
         }
-      else if (optind < argc)
+      else if (argi < argc)
         {
           const char *filename;
-          filename = argv[optind];
+          filename = argv[argi];
           if (js_eval_file(ctx, filename, 1))
             {
               goto fail;