[Piglit] [PATCH] egl: fix egl-query-surface argv parsing

nobled nobled at dreamwidth.org
Tue Nov 15 14:09:36 PST 2011


This fixes:
1. If you passed any option not recognized by egl-query-surface,
but that *is* recognized by egl_util_run() like '-auto', it would
usually fail with usage().
2. If it didn't fail, it was because the loop skips over the next
argument after it finds one it recognizes.
3. If a recognized argument is the last/only argument in argv,
egl_util_run() would segfault with a null deref in strcmp() because
argc would be off by one, because of problem 2.

The only way the test didn't crash or fail was if two arguments
were passed in this exact order:

bin/egl-query-surface --bad-surface -auto
---
 tests/egl/egl-query-surface.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/egl/egl-query-surface.c b/tests/egl/egl-query-surface.c
index c590018..2ea15f0 100644
--- a/tests/egl/egl-query-surface.c
+++ b/tests/egl/egl-query-surface.c
@@ -153,7 +153,7 @@ parse_args(char **argv,
 	/* Count of parsed args, excluding -auto. */
 	int num_parsed_args = 0;

-	for (i = 1; argv[i] != NULL; ++i) {
+	for (i = 1; argv[i] != NULL;) {
 		const char *arg = argv[i];
 		if (!strncmp(arg, "--bad-surface", 13)) {
 			++num_parsed_args;
@@ -173,7 +173,7 @@ parse_args(char **argv,
 			*out_test = query_height;
 		} else {
 		   /* Unrecognized argument. */
-		   usage_error();
+		   ++i;
 		}
 	}

@@ -181,7 +181,7 @@ parse_args(char **argv,
 	   usage_error();
 	}

-	*out_argc = i;
+	*out_argc -= num_parsed_args;
 }

 int
-- 
1.7.4.1


More information about the Piglit mailing list