[svn:parrot] r49278 - trunk/src
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Thu Sep 23 23:23:39 UTC 2010
Author: chromatic
Date: Thu Sep 23 23:23:39 2010
New Revision: 49278
URL: https://trac.parrot.org/parrot/changeset/49278
Log:
[main] Improved --gc-threshold arg processing.
r42946 was okay, except for the parts that weren't. This code is more explicit
about what's necessary and why. t/run/options.t should still pass after this
commit.
We need more testing of command-line options.
Modified:
trunk/src/main.c
Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c Thu Sep 23 20:37:39 2010 (r49277)
+++ trunk/src/main.c Thu Sep 23 23:23:39 2010 (r49278)
@@ -400,14 +400,28 @@
}
break;
}
- /* don't overflow argv; check length first */
- else if (argc > arg + 14
- && !strncmp(arg, "--gc-threshold", 14)) {
- if ((arg = strrchr(arg, '=')))
- ++arg;
- else
- arg = argv[++pos];
+ /* arg should start with --gc-threshold *and* contain more chars */
+ else if (strncmp(arg, "--gc-threshold", 14) == 0) {
+
+ /* the next character could be '=' */
+ if (arg[14] == '=') {
+ arg++;
+ }
+
+ /* or the end of the string... */
+ else if (arg[14] == '\0'
+
+ /* and there's another argument */
+ && pos < argc - 1) {
+ arg = argv[++pos];
+ }
+
+ /* ANYTHING ELSE IS WRONG */
+ else {
+ fprintf(stderr, "--gc-threshold needs an argument" );
+ exit(EXIT_FAILURE);
+ }
if (is_all_digits(arg)) {
interp->gc_threshold = strtoul(arg, NULL, 10);
More information about the parrot-commits
mailing list