This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/3] posix: Remove dynamic memory allocation from execl{e,p}


On 02/26/2016 05:56 AM, Adhemerval Zanella wrote:
+  for (i = 1; i < argc; i++)
+     argv[i] = va_arg (ap, char *);
+  argv[i] = NULL;

Change "i < argc" to "i <= argc" and remove the "argv[i] = NULL;", as that's a bit simpler and faster.

+  int i;
+  char *argv[argc + 1];
+  char **envp;
+  va_start (ap, arg);
+  argv[0] = (char *) arg;
+  for (i = 1; i <= argc; i++)

This sort of thing has undefined behavior on x86-64 if argc == INT_MAX. You can fix this by changing the type of argc and of i from int to ptrdiff_t.

+      if (argc == INT_MAX)
  	{
+	  errno = E2BIG;
+	  return -1;
  	}

Doesn't that have undefined behavior? My impression from C11 is that since the function has called va_start it must call va_end before returning.

+      continue;
      }

That 'continue;' is redundant and should be removed.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]