xiaoxiang781216 commented on code in PR #20599:
URL: https://github.com/apache/nuttx/pull/20599#discussion_r4266065915


##########
binfmt/binfmt_copyargv.c:
##########
@@ -35,12 +35,77 @@
 
 #include "binfmt.h"
 
-#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) && 
!defined(CONFIG_BINFMT_DISABLE)
+#ifndef CONFIG_BINFMT_DISABLE

Review Comment:
   remove the check



##########
binfmt/script.c:
##########
@@ -67,15 +68,85 @@ static struct binfmt_s g_script_binfmt =
  * Private Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: script_setargv
+ *
+ * Description:
+ *   Set binp->argv to: interp, arg (if not NULL), filename, then the
+ *   entries after the first of the old list (a script whose interpreter is
+ *   a script).  All strings are copied into one allocation.
+ *
+ ****************************************************************************/
+
+static int script_setargv(FAR struct binary_s *binp, FAR const char *interp,
+                          FAR const char *arg, FAR const char *filename)
+{
+  FAR char **old = binp->argv;
+  FAR const char *src[3];
+  FAR char **list;
+  FAR char *str;
+  size_t size = 0;
+  int nsrc = 0;
+  int nold = 0;
+  int nargs;
+  int i;
+
+  src[nsrc++] = interp;
+  if (arg != NULL)
+    {
+      src[nsrc++] = arg;
+    }
+
+  src[nsrc++] = filename;
+
+  if (old != NULL)
+    {
+      while (old[nold] != NULL)
+        {
+          nold++;
+        }
+    }
+
+  nargs = nsrc + (nold > 1 ? nold - 1 : 0);
+  for (i = 0; i < nsrc; i++)
+    {
+      size += strlen(src[i]) + 1;
+    }
+
+  for (i = 1; i < nold; i++)
+    {
+      size += strlen(old[i]) + 1;
+    }
+
+  list = kmm_malloc((nargs + 1) * sizeof(FAR char *) + size);
+  if (list == NULL)
+    {
+      return -ENOMEM;
+    }
+
+  str = (FAR char *)&list[nargs + 1];
+  for (i = 0; i < nargs; i++)
+    {
+      FAR const char *s = i < nsrc ? src[i] : old[i - nsrc + 1];
+
+      list[i] = strcpy(str, s);
+      str += strlen(s) + 1;
+    }
+
+  list[nargs]      = NULL;

Review Comment:
   remove the extra spaces



-- 
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