[Piglit] [PATCH 1/3] glslparsertest: Fix parsing of GL_SHADING_LANGUAGE_VERSION in GLES.

Paul Berry stereotype441 at gmail.com
Thu Feb 14 11:14:37 PST 2013


In desktop GL, glGetString(GL_SHADING_LANGUAGE_VERSION) returns a
string that begins with the supported version number.  But in GLES,
the version number is preceded by the text "OpenGL ES GLSL ES ".  This
was causing glslparsertest to fail to parse the implementation's
supported GLSL version, and that in turn caused parse_glsl_version()
function to access uninitialized memory.

This patch splits parse_glsl_version() into two functions:
parse_glsl_version_number(), which parses the bare version number, and
parse_glsl_version_string(), which expects the prefix "OpenGL ES GLSL
ES " when compiled for GLES testing.
---
 tests/glslparsertest/glslparsertest.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/tests/glslparsertest/glslparsertest.c b/tests/glslparsertest/glslparsertest.c
index ff32da7..cc37a35 100644
--- a/tests/glslparsertest/glslparsertest.c
+++ b/tests/glslparsertest/glslparsertest.c
@@ -35,12 +35,13 @@
 
 #include "piglit-util-gl-common.h"
 
-static unsigned parse_glsl_version(const char *str);
+static unsigned parse_glsl_version_number(const char *str);
 
 PIGLIT_GL_TEST_CONFIG_BEGIN
 
 	if (argc > 3) {
-		const unsigned int int_version = parse_glsl_version(argv[3]);
+		const unsigned int int_version
+			= parse_glsl_version_number(argv[3]);
 
 		switch (int_version) {
 		case 110:
@@ -302,7 +303,7 @@ int process_options(int argc, char **argv)
 }
 
 static unsigned
-parse_glsl_version(const char *str)
+parse_glsl_version_number(const char *str)
 {
 	unsigned major;
 	unsigned minor;
@@ -311,6 +312,26 @@ parse_glsl_version(const char *str)
 	return (major * 100) + minor;
 }
 
+
+static unsigned
+parse_glsl_version_string(const char *str)
+{
+#if defined(PIGLIT_USE_OPENGL_ES2) || defined(PIGLIT_USE_OPENGL_ES3)
+	/* In GLSL ES, the string returned by
+	 * glGetString(GL_SHADING_LANGUAGE_VERSION) is prefixed by
+	 * some text.  Verify that the expected text is there and skip
+	 * it before calling parse_glsl_version_number().
+	 */
+	const char *expected_prefix = "OpenGL ES GLSL ES ";
+	if (strncmp(str, expected_prefix, strlen(expected_prefix)) != 0) {
+		printf("Ill-formed GLSL version string: %s\n", str);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+	str += strlen(expected_prefix);
+#endif
+	return parse_glsl_version_number(str);
+}
+
 void
 piglit_init(int argc, char**argv)
 {
@@ -334,7 +355,7 @@ piglit_init(int argc, char**argv)
 		usage(argv[0]);
 
 	if (argc > 3)
-		requested_version = parse_glsl_version(argv[3]);
+		requested_version = parse_glsl_version_number(argv[3]);
 
 	gl_version_times_10 = piglit_get_gl_version();
 
@@ -349,7 +370,7 @@ piglit_init(int argc, char**argv)
 		glGetString(GL_SHADING_LANGUAGE_VERSION);
 
 	if (glsl_version_string != NULL)
-		glsl_version = parse_glsl_version(glsl_version_string);
+		glsl_version = parse_glsl_version_string(glsl_version_string);
 
 	if (requested_version == 100) {
 		piglit_require_extension("GL_ARB_ES2_compatibility");
-- 
1.8.1.3



More information about the Piglit mailing list