New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
memmem.c -Wpointer-bool-conversion warning #31
Comments
It's intentional that |
4a95c63 turned it into:
|
Hm... do you happen to know the appropriate fix? |
My next guess would be to move that line to the beginning of the function. Does that work for you? |
Makes no difference. See llvm-mirror/clang@01ad089. As a last resort, you could enable |
Hm... I don't understand why those pointers should be tautologically non-null at the beginning of the function, before the variable declarations. (Later on, it makes sense to assume they're non-null, since otherwise undefined behavior would be triggered by some dereferences.) I would like to understand what the compilers are complaining about and fix it properly! |
To avoid an error on my part, this is what you wanted me to try, right? diff --git a/src/c/memmem.c b/src/c/memmem.c
index 891b211..99163dd 100644
--- a/src/c/memmem.c
+++ b/src/c/memmem.c
@@ -60,6 +60,10 @@ __RCSID("$NetBSD$");
void *
memmem(const void *b1, size_t len1, const void *b2, size_t len2)
{
+ /* Sanity check */
+ if(!(b1 != NULL && b2 != NULL && len1 != 0 && len2 != 0))
+ return NULL;
+
/* Initialize search pointer */
char *sp = (char *) b1;
@@ -69,10 +73,6 @@ memmem(const void *b1, size_t len1, const void *b2, size_t len2)
/* Intialize end of search address space pointer */
char *eos = sp + len1 - len2;
- /* Sanity check */
- if(!(b1 != NULL && b2 != NULL && len1 != 0 && len2 != 0))
- return NULL;
-
while (sp <= eos) {
if (*sp == *pp)
if (memcmp(sp, pp, len2) == 0) |
Right. |
This occurs because in some libcs (including glibc), string.h declares
If a declaration like this is in scope, Clang assumes that the pointer arguments are nonnull, and it helpfully warns that the user may have made a mistake somewhere. I’d prefer to fix this by renaming our |
Thanks for the diagnosis. I've pushed a name change. @Tuncer, can you confirm that the name change fixes the issue for you? |
Thanks, confirmed. |
Just a thought: should the file be renamed ( |
Hm... it doesn't seem too important to optimize the file name, since it won't even be preserved in the compiled library, outside of debug symbols. |
Unfortunately -Werror is enabled by default, and when compiled with gcc-6.1 or clang-3.8, the following warning will prevent a successful build:
The text was updated successfully, but these errors were encountered: