Mesa (master): i965: Fix memmem compiler warnings.

Eric Anholt anholt at kemper.freedesktop.org
Tue Oct 24 17:51:44 UTC 2017


Module: Mesa
Branch: master
Commit: e91c3540fc620b39a16d5bce9fd75aa0ddd7ed7e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e91c3540fc620b39a16d5bce9fd75aa0ddd7ed7e

Author: Eric Anholt <eric at anholt.net>
Date:   Tue Oct 17 15:41:25 2017 -0700

i965: Fix memmem compiler warnings.

gcc is throwing this warning in my meson build:

../src/intel/compiler/brw_eu_validate.c:50:11: warning
argument 1 null where non-null expected [-Wnonnull]
    return memmem(haystack.str, haystack.len,
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                  needle.str, needle.len) != NULL;
                                  ~~~~~~~~~~~~~~~~~~~~~~~

The first check for CONTAINS has a NULL error_msg.str and 0 len.  The
glibc implementation will exit without looking at any haystack bytes if
haystack.len < needle.len, so this was safe, but silence the warning
anyway by guarding against implementation variablility.

Fixes: 122ef3799d56 ("i965: Only insert error message if not already present")
Reviewed-by: Matt Turner <mattst88 at gmail.com>

---

 src/intel/compiler/brw_eu_validate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/intel/compiler/brw_eu_validate.c b/src/intel/compiler/brw_eu_validate.c
index 9f72c650dd..f359599c38 100644
--- a/src/intel/compiler/brw_eu_validate.c
+++ b/src/intel/compiler/brw_eu_validate.c
@@ -47,7 +47,8 @@ cat(struct string *dest, const struct string src)
 static bool
 contains(const struct string haystack, const struct string needle)
 {
-   return memmem(haystack.str, haystack.len, needle.str, needle.len) != NULL;
+   return haystack.str && memmem(haystack.str, haystack.len,
+                                 needle.str, needle.len) != NULL;
 }
 #define CONTAINS(haystack, needle) \
    contains(haystack, (struct string){needle, strlen(needle)})




More information about the mesa-commit mailing list