[Piglit] [PATCH] Fix infinite loop in piglit_is_extension_in_string.

Paul Berry stereotype441 at gmail.com
Mon Dec 19 21:46:29 PST 2011


If piglit_is_extension_in_string() finds an extension whose name
begins with the name it is searching for, but is not equal to the name
it is searching for (e.g. it is searching for EXT_transform_feedback
but it finds EXT_transform_feedback2), we need it to advance by one
character before restarting the search, otherwise it will loop
indefinitely.

Prevents a hang when running some transform feedback tests on nVidia's
proprietary Linux driver.
---
 tests/util/piglit-util.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 65b02f5..3241528 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -145,15 +145,23 @@ bool piglit_is_extension_in_string(const char *haystack, const char *needle)
 	if (needle_len == 0)
 		return false;
 
-	while (haystack != NULL) {
+	while (true) {
 		const char *const s = strstr(haystack, needle);
 
-		if (s != NULL
-		    && (s[needle_len] == ' ' || s[needle_len] == '\0')) {
+		if (s == NULL)
+			return false;
+
+		if (s[needle_len] == ' ' || s[needle_len] == '\0') {
 			return true;
 		}
 
-		haystack = s;
+		/* strstr found an extension whose name begins with
+		 * needle, but whose name is not equal to needle.
+		 * Restart the search at s + 1 so that we don't just
+		 * find the same extension again and go into an
+		 * infinite loop.
+		 */
+		haystack = s + 1;
 	}
 
 	return false;
-- 
1.7.6.4



More information about the Piglit mailing list