Skip to content
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

Tests fail to compile: error: comparison between pointer and integer ('void *' and 'int') #213

Open
yurivict opened this issue Jan 10, 2024 · 2 comments

Comments

@yurivict
Copy link

All these errors are due to the obvious type mismatch in the code:

cd /usr/ports/net/usockets/work/uSockets-0.8.7 &&  c++ -o test tests/sni_test.c /usr/ports/net/usockets/work/stage/usr/local/lib/libuSockets.so &&  ./test
c++: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
tests/sni_test.c:25:9: error: no matching function for call to 'sni_add'
        assert(sni_add(sni, "*.google.com", 13) == 0);
               ^~~~~~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:4:5: note: candidate function not viable: no known conversion from 'int' to 'void *' for 3rd argument
int sni_add(void *sni, const char *hostname, void *user);
    ^
tests/sni_test.c:26:9: error: no matching function for call to 'sni_add'
        assert(sni_add(sni, "test.google.com", 14) == 0);
               ^~~~~~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:4:5: note: candidate function not viable: no known conversion from 'int' to 'void *' for 3rd argument
int sni_add(void *sni, const char *hostname, void *user);
    ^
tests/sni_test.c:29:9: error: no matching function for call to 'sni_add'
        assert(sni_add(sni, "*.google.com", 15) != 0);
               ^~~~~~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:4:5: note: candidate function not viable: no known conversion from 'int' to 'void *' for 3rd argument
int sni_add(void *sni, const char *hostname, void *user);
    ^
tests/sni_test.c:30:46: error: comparison between pointer and integer ('void *' and 'int')
        assert(sni_find(sni, "anything.google.com") == 13);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:32:42: error: comparison between pointer and integer ('void *' and 'int')
        assert(sni_find(sni, "docs.google.com") == 13);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:33:39: error: comparison between pointer and integer ('void *' and 'int')
        assert(sni_find(sni, "*.google.com") == 13);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:34:42: error: comparison between pointer and integer ('void *' and 'int')
        assert(sni_find(sni, "test.google.com") == 14);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:36:42: error: comparison between pointer and integer ('void *' and 'int')
        assert(sni_find(sni, "yolo.google.com") == 13);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:39:44: error: comparison between pointer and integer ('void *' and 'int')
        assert(sni_remove(sni, "test.google.com") == 14);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:40:42: error: comparison between pointer and integer ('void *' and 'int')
        assert(sni_find(sni, "test.google.com") == 13);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:41:41: error: comparison between pointer and integer ('void *' and 'int')
        assert(sni_remove(sni, "*.google.com") == 13);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:45:9: error: no matching function for call to 'sni_add'
        assert(sni_add(sni, "www.google.com", 16) == 0);
               ^~~~~~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:4:5: note: candidate function not viable: no known conversion from 'int' to 'void *' for 3rd argument
int sni_add(void *sni, const char *hostname, void *user);
    ^
tests/sni_test.c:46:9: error: no matching function for call to 'sni_add'
        assert(sni_add(sni, "www.google.com.au.ck.uk", 17) == 0);
               ^~~~~~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:4:5: note: candidate function not viable: no known conversion from 'int' to 'void *' for 3rd argument
int sni_add(void *sni, const char *hostname, void *user);
    ^
tests/sni_test.c:47:41: error: comparison between pointer and integer ('void *' and 'int')
        assert(sni_find(sni, "www.google.com") == 16);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:48:50: error: comparison between pointer and integer ('void *' and 'int')
        assert(sni_find(sni, "www.google.com.au.ck.uk") == 17);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:50:52: error: comparison between pointer and integer ('void *' and 'int')
        assert(sni_remove(sni, "www.google.com.au.ck.uk") == 17);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
tests/sni_test.c:51:41: error: comparison between pointer and integer ('void *' and 'int')
        assert(sni_find(sni, "www.google.com") == 16);
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
/usr/include/assert.h:55:21: note: expanded from macro 'assert'
#define assert(e)       ((e) ? (void)0 : __assert(__func__, __FILE__, \
                          ^
17 errors generated.

Version: 0.8.7
clang-16
FreeBSD 14.0

@uNetworkingAB
Copy link
Contributor

I think your issue is this

c++: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]

Those conversions are not issues in C.

@yurivict
Copy link
Author

The clang-16 C compiler complains the same way:

===>  Testing for usockets-0.8.7
cd /usr/ports/net/usockets/work/uSockets-0.8.7 &&  cc -O2 -pipe  -fstack-protector-strong -fno-strict-aliasing  -o test tests/sni_test.c /usr/ports/net/usockets/work/stage/usr/local/lib/libuSockets.so &&  ./test
tests/sni_test.c:25:38: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'void *' [-Wint-conversion]
        assert(sni_add(sni, "*.google.com", 13) == 0);
                                            ^~

This is an invalid C code.

Also why is the extern "C" { block in the C file? This is also invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants