summaryrefslogtreecommitdiff
path: root/run.c
diff options
context:
space:
mode:
authorEmil Velikov <emil.velikov@collabora.com>2017-08-17 16:45:32 +0100
committerEmil Velikov <emil.l.velikov@gmail.com>2017-08-26 11:09:34 +0100
commitc7d6c2aacaf7c07004d422922079422196e111fa (patch)
treeae7407649350eef3aca312dd9ca7319dde35d58a /run.c
parent1610dbf88c76536a41e217fa64232fcdfe9a7e17 (diff)
run: add extension_in_string() helper
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 (from piglit) that correctly handles this and use it. v2: Drop unintentional whitespace changes (Eric) Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com> Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Diffstat (limited to 'run.c')
-rw-r--r--run.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/run.c b/run.c
index 4ec5fdd..24e9817 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,
@@ -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)
};
const char *egl_extension_string = eglQueryString(egl_dpy, EGL_EXTENSIONS);
for (int i = 0; i < ARRAY_SIZE(egl_extension); i++) {
- if (strstr(egl_extension_string, egl_extension[i]) == NULL) {
+ if (!extension_in_string(egl_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(compat.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;