Skip to contentSkip to conversation

ext-toolchain-wrapper.c: Handle an arbitrary amount of arguments

PATCH Superseded Daniel Nyström 1 participant 2 messages Jun 21, 2011

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ext-toolchain-wrapper.c: Handle an arbitrary amount of arguments

Even though MAXARGS 1000 seems large, it wasn't enought for at least QtWebKit package. This new version does not have any predefined limits.

Closes #3907

Many thanks to Thomas for tracing the source of the build error.

---

New in v2:
* Check for malloc returning NULL
* Remove unused variable 'i'
* Add closing bug # in commit message

.../toolchain-external/ext-toolchain-wrapper.c | 30 +++++++++++++------

 1 files changed, 20 insertions(+), 10 deletions(-)
toolchain/toolchain-external/ext-toolchain-wrapper.c +20 -10
index a485e74..91732b0 100644
@@ -4,6 +4,7 @@
  * to ensure the external toolchain uses the correct configuration.
  *
  * (C) 2011 Peter Korsgaard <[email protected]>
+ * (C) 2011 Daniel Nystr?m <[email protected]>
  *
  * This file is licensed under the terms of the GNU General Public License
  * version 2.  This program is licensed "as is" without any warranty of any
@@ -14,12 +15,11 @@
 #include <string.h>
 #include <limits.h>
 #include <unistd.h>
-
-#define MAXARGS 1000
+#include <stdlib.h>
 
 static char path[PATH_MAX] = BR_CROSS_PATH;
 
-static char *args[MAXARGS] = {
+static char *predef_args[] = {
 	path,
 	"--sysroot", BR_SYSROOT,
 #ifdef BR_ARCH
@@ -55,21 +55,31 @@ static const char *get_basename(const char *name)
 int main(int argc, char **argv)
 {
 	int i;
+	char **args, **cur;
 
-	for (i=0; args[i]; i++);
-
-	if ((argc+i) >= MAXARGS) {
-		fputs("Too many arguments\n", stderr);
-		return 1;
+	cur = args = malloc(sizeof(predef_args) + (sizeof(char *) * argc));
+	if (args == NULL) {
+		perror("malloc");
+		abort();
 	}
 
-	/* forward args */
-	memcpy(&args[i], &argv[1], sizeof(argv[0]) * (argc - 1));
+	/* start with predefined args */
+	memcpy(cur, predef_args, sizeof(predef_args));
+	cur += sizeof(predef_args) / sizeof(predef_args[0]);
+
+	/* append forward args */
+	memcpy(cur, &argv[1], sizeof(char *) * (argc - 1));
+	cur += argc - 1;
+
+	/* finish with NULL termination */
+	*cur = NULL;
 
 	strcat(path, get_basename(argv[0]));
 
 	if (execv(path, args))
 		perror(path);
 
+	free(args);
+
 	return 2;
 }
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH v2 1/1 ext-toolchain-wrapper.c: Handle an arbitrary amount of arguments

Den 21 juni 2011 21:47 skrev Daniel Nystr?m <[email protected]>:

Quoted 7 lines

Even though MAXARGS 1000 seems large, it wasn't enought for at least QtWebKit package. This new version does not have any predefined limits.

Closes #3907

Many thanks to Thomas for tracing the source of the build error.

Quoted 8 lines

---

New in v2:
?* Check for malloc returning NULL
?* Remove unused variable 'i'
?* Add closing bug # in commit message

Please ignore. Last changes (mentioned above) wasn't applied in the patch. v3 on it's way.