From: Emil Velikov <emil.veli...@collabora.com> memmem() does not attribute what the character after the searched string is. Thus it will flag even when haystack is "foobar" while we're looking for "foo".
Pull a small helper (based on piglit) that correctly handles this and use it. Note: when parsing through the shader we have a non-zero terminated needle, let's keep the memmem in there for now. Signed-off-by: Emil Velikov <emil.veli...@collabora.com> --- run.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/run.c b/run.c index d0d4598..0691d33 100644 --- a/run.c +++ b/run.c @@ -69,6 +69,35 @@ struct shader { int type; }; +static bool +extension_in_string(const char *haystack, const char *needle) +{ + const unsigned needle_len = strlen(needle); + + if (needle_len == 0) + return false; + + while (true) { + const char *const s = strstr(haystack, needle); + + if (s == NULL) + return false; + + if (s[needle_len] == ' ' || s[needle_len] == '\0') + return true; + + /* strstr found an extension whose name begins with + * needle, but whose name is not equal to needle. + * Restart the search at s + needle_len so that we + * don't just find the same extension again and go + * into an infinite loop. + */ + haystack = s + needle_len; + } + + return false; +} + static struct shader * get_shaders(const struct context_info *core, const struct context_info *compat, const char *text, size_t text_size, @@ -141,8 +170,8 @@ get_shaders(const struct context_info *core, const struct context_info *compat, extension_text += 1; const char *newline = memchr(extension_text, '\n', end_text - extension_text); - if (memmem(info->extension_string, info->extension_string_len, - extension_text, newline - extension_text) == NULL) { + if (memmem(info->extension_string, info->extension_string_len, + extension_text, newline - extension_text) == NULL) { fprintf(stderr, "SKIP: %s requires unavailable extension %.*s\n", shader_name, (int)(newline - extension_text), extension_text); return NULL; @@ -415,7 +444,7 @@ main(int argc, char **argv) return -1; } - if (!strstr(client_extensions, "EGL_MESA_platform_gbm")) { + if (!extension_in_string(client_extensions, "EGL_MESA_platform_gbm")) { fprintf(stderr, "ERROR: Missing EGL_MESA_platform_gbm\n"); return -1; } @@ -458,7 +487,7 @@ main(int argc, char **argv) }; for (int i = 0; i < ARRAY_SIZE(egl_extension); i++) { const char *extension_string = eglQueryString(egl_dpy, EGL_EXTENSIONS); - if (strstr(extension_string, egl_extension[i]) == NULL) { + if (!extension_in_string(extension_string, egl_extension[i])) { fprintf(stderr, "ERROR: Missing %s\n", egl_extension[i]); ret = -1; goto egl_terminate; @@ -530,8 +559,7 @@ main(int argc, char **argv) core.max_glsl_version = get_glsl_version(); - if (memmem(core.extension_string, core.extension_string_len, - "GL_KHR_debug", strlen("GL_KHR_debug")) == NULL) { + if (!extension_in_string(core.extension_string, "GL_KHR_debug")) { fprintf(stderr, "ERROR: Missing GL_KHR_debug\n"); ret = -1; goto egl_terminate; @@ -556,8 +584,7 @@ main(int argc, char **argv) compat.max_glsl_version = get_glsl_version(); - if (memmem(compat.extension_string, compat.extension_string_len, - "GL_KHR_debug", strlen("GL_KHR_debug")) == NULL) { + if (!extension_in_string(compat.extension_string, "GL_KHR_debug")) { fprintf(stderr, "ERROR: Missing GL_KHR_debug\n"); ret = -1; goto egl_terminate; -- 2.13.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev