lib: fix warnings about undefined macros #1362

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

@MarcelRaad
Member
MarcelRaad commented Mar 27, 2017 edited

At least under Windows, there is no SIZEOF_LONG, so it evaluates to 0 even
though sizeof(int) == sizeof(long). This should probably have been
CURL_SIZEOF_LONG, but the type of timeout_ms changed from long to time_t
anyway.
Also defaulted USE_NTLM2SESSION to 0 if it's not defined so that MSVC warning
C4668 about implicitly replacing undefined macros with '0' can now be enabled.

@MarcelRaad, thanks for your PR! By analyzing the history of the files in this pull request, we identified @bagder, @yangtse and @captain-caveman2k to be potential reviewers.

Owner
jay commented Mar 28, 2017

I think we should require for all build systems either CURL_SIZEOF_LONG or SIZEOF_LONG and whichever one is required outlaw the other. Same for TIME_T.

Member

Yes, I've verified that SIZEOF_SIZE_T is defined in all config headers and SIZEOF_LONG isn't used anywhere else (but is defined in config-vxworks.h and curl_config.h). So it looks like CURL_SIZEOF_LONG would win over SIZEOF_LONG at this time.

But I find it a bit strange that CURL_SIZEOF_LONG is the only SIZEOF constant for a built-in type that has a CURL_ prefix and is defined in curlbuild.h. It was added there in feb03e4 and SIZEOF_LONG removed from config-symbian.h and config-tpf.h. 14240e9 initially moved only the curl-specific constants to curlbuild.h.

Owner
bagder commented Mar 28, 2017 edited

Symbols defined in our public header files must be "curl" prefixed, so if it is to be there it must be CURL_SIZEOF_LONG. But then I can't see any strong reason why it needs to be public in the first place...

lib/curl_ntlm_core.h
@@ -53,6 +53,10 @@
#define USE_NTLM2SESSION 1
#endif
+#if !defined(USE_NTLM2SESSION)
+#define USE_NTLM2SESSION 0
bagder
bagder Mar 29, 2017 Owner

So what's the exact warning this fixes? I only see a !defined(USE_NTLM2SESSION) use of this and that looks perfectly fine to me?

jay
jay Mar 29, 2017 Owner

Depending on how libcurl is built with ntlm USE_NTLM2SESSION is defined 0 or 1 or undefined. In ntlm code I notice there is a lot of #if FOO instead of #if defined(FOO). For example there is this twice:
#if USE_NTRESPONSES && USE_NTLM2SESSION
He has a compiler switch that catches when FOO macro is evaluated to 0 due to undefined FOO

bagder
bagder Mar 29, 2017 Owner

I would prefer that we rather make sure to depend on features with #ifdef so that we #undef features we don't have and we #define those we have. I think that's the pattern used more widely already. Defining to zero when we don't have it is an anomaly.

MarcelRaad
MarcelRaad Mar 29, 2017 Member

Yes, exactly. All the macros defined in curl_ntlm_core.h and used in curl_ntlm_core.c and vauth/ntlm.c are checked with #if instead of #ifdef:
USE_NTLM_V2
USE_NTRESPONSES
USE_NTLM2SESSION
Seems like this is for historical reasons, they were always defined to 1 when introduced in 2006.

I'll glady change this in a separate pull request and remove the curl_ntlm_core.h changes from this one.

@@ -164,7 +164,7 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
int r;
int ret;
-#if SIZEOF_LONG != SIZEOF_INT
+#if SIZEOF_TIME_T != SIZEOF_INT
bagder
bagder Mar 29, 2017 Owner

Oops, what a bug!

@MarcelRaad MarcelRaad added a commit to MarcelRaad/curl that referenced this pull request Mar 29, 2017
@MarcelRaad MarcelRaad NTLM: check for features with #ifdef instead of #if
Feature defines are normally checked with #ifdef instead of #if in the rest of
the codebase. Additionally, some compilers warn when a macro is implicitly
evaluated to 0 because it is not defined, which was the case here.

Ref: curl#1362 (comment)
ac50789
@MarcelRaad MarcelRaad added a commit to MarcelRaad/curl that referenced this pull request Mar 29, 2017
@MarcelRaad MarcelRaad NTLM: check for features with #ifdef instead of #if
Feature defines are normally checked with #ifdef instead of #if in the rest of
the codebase. Additionally, some compilers warn when a macro is implicitly
evaluated to 0 because it is not defined, which was the case here.

Ref: curl#1362 (comment)
Closes curl#1367
9bc92ee
@MarcelRaad MarcelRaad added a commit to MarcelRaad/curl that referenced this pull request Mar 29, 2017
@MarcelRaad MarcelRaad select: use correct SIZEOF_ constant
At least under Windows, there is no SIZEOF_LONG, so it evaluates to 0 even
though sizeof(int) == sizeof(long). This should probably have been
CURL_SIZEOF_LONG, but the type of timeout_ms changed from long to time_t
anyway.
This triggered MSVC warning C4668 about implicitly replacing undefined
macros with '0'.

Closes curl#1362
0c460a4
@MarcelRaad MarcelRaad select: use correct SIZEOF_ constant
At least under Windows, there is no SIZEOF_LONG, so it evaluates to 0 even
though sizeof(int) == sizeof(long). This should probably have been
CURL_SIZEOF_LONG, but the type of timeout_ms changed from long to time_t
anyway.
This triggered MSVC warning C4668 about implicitly replacing undefined
macros with '0'.

Closes curl#1362
1ff689a
Member

Updated and rebased after merging #1367 . Now only the change from SIZEOF_LONG to SIZEOF_TIME_T remains.

@jay
jay approved these changes Mar 29, 2017 View changes
@bagder
bagder approved these changes Mar 29, 2017 View changes

Nice catch btw!

@MarcelRaad MarcelRaad added a commit to MarcelRaad/curl that referenced this pull request Mar 30, 2017
@MarcelRaad MarcelRaad select: use correct SIZEOF_ constant
At least under Windows, there is no SIZEOF_LONG, so it evaluates to 0 even
though sizeof(int) == sizeof(long). This should probably have been
CURL_SIZEOF_LONG, but the type of timeout_ms changed from long to time_t
anyway.
This triggered MSVC warning C4668 about implicitly replacing undefined
macros with '0'.

Closes curl#1362
1b4b2c1
@MarcelRaad MarcelRaad added a commit that closed this pull request Mar 30, 2017
@MarcelRaad MarcelRaad select: use correct SIZEOF_ constant
At least under Windows, there is no SIZEOF_LONG, so it evaluates to 0 even
though sizeof(int) == sizeof(long). This should probably have been
CURL_SIZEOF_LONG, but the type of timeout_ms changed from long to time_t
anyway.
This triggered MSVC warning C4668 about implicitly replacing undefined
macros with '0'.

Closes #1362
1b4b2c1
@MarcelRaad MarcelRaad deleted the MarcelRaad:fix_undefined_macros branch Apr 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment