summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJay Satiro <raysatiro@yahoo.com>2019-11-30 03:29:36 -0500
committerJay Satiro <raysatiro@yahoo.com>2019-12-01 19:01:02 -0500
commit9c1806ae4684ec5ef1aeb39bb9f15cece1c27256 (patch)
tree519c34c7411ae2afda27b38500f77d456bb8cad9 /lib
parent0436d4438a9dbfd5dc1364de31281505c7915b25 (diff)
downloadcurl-9c1806ae4684ec5ef1aeb39bb9f15cece1c27256.tar.gz
build: Disable Visual Studio warning "conditional expression is constant"
- Disable warning C4127 "conditional expression is constant" globally in curl_setup.h for when building with Microsoft's compiler. This mainly affects building with the Visual Studio project files found in the projects dir. Prior to this change the cmake and winbuild build systems already disabled 4127 globally for when building with Microsoft's compiler. Also, 4127 was already disabled for all build systems in the limited circumstance of the WHILE_FALSE macro which disabled the warning specifically for while(0). This commit removes the WHILE_FALSE macro and all other cruft in favor of disabling globally in curl_setup. Background: We have various macros that cause 0 or 1 to be evaluated, which would cause warning C4127 in Visual Studio. For example this causes it: #define Curl_resolver_asynch() 1 Full behavior is not clearly defined and inconsistent across versions. However it is documented that since VS 2015 Update 3 Microsoft has addressed this somewhat but not entirely, not warning on while(true) for example. Prior to this change some C4127 warnings occurred when I built with Visual Studio using the generated projects in the projects dir. Closes https://github.com/curl/curl/pull/4658
Diffstat (limited to 'lib')
-rw-r--r--lib/CMakeLists.txt1
-rw-r--r--lib/cookie.c2
-rw-r--r--lib/curl_multibyte.h4
-rw-r--r--lib/curl_setup.h10
-rw-r--r--lib/curl_setup_once.h25
-rw-r--r--lib/doh.c2
-rw-r--r--lib/http2.c2
-rw-r--r--lib/ldap.c2
-rw-r--r--lib/memdebug.h2
-rw-r--r--lib/mprintf.c2
-rw-r--r--lib/select.h2
-rw-r--r--lib/sendf.c2
-rw-r--r--lib/sha256.c4
-rw-r--r--lib/telnet.c4
-rw-r--r--lib/transfer.c2
-rw-r--r--lib/url.c2
-rw-r--r--lib/vquic/ngtcp2.c2
-rw-r--r--lib/vquic/quiche.c2
-rw-r--r--lib/vssh/libssh.c2
-rw-r--r--lib/vtls/nss.c2
-rw-r--r--lib/vtls/openssl.c4
21 files changed, 33 insertions, 47 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index eca9a8af9..a9c90b665 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -20,7 +20,6 @@ list(APPEND HHEADERS
if(MSVC)
list(APPEND CSOURCES libcurl.rc)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127")
endif()
# SET(CSOURCES
diff --git a/lib/cookie.c b/lib/cookie.c
index c9e420ad4..0091132aa 100644
--- a/lib/cookie.c
+++ b/lib/cookie.c
@@ -1227,7 +1227,7 @@ static int cookie_sort_ct(const void *p1, const void *p2)
if(!d->field) \
goto fail; \
} \
- } WHILE_FALSE
+ } while(0)
static struct Cookie *dup_cookie(struct Cookie *src)
{
diff --git a/lib/curl_multibyte.h b/lib/curl_multibyte.h
index e30008be4..5225e1811 100644
--- a/lib/curl_multibyte.h
+++ b/lib/curl_multibyte.h
@@ -62,7 +62,7 @@ char *Curl_convert_wchar_to_UTF8(const wchar_t *str_w);
#define Curl_convert_UTF8_to_tchar(ptr) Curl_convert_UTF8_to_wchar((ptr))
#define Curl_convert_tchar_to_UTF8(ptr) Curl_convert_wchar_to_UTF8((ptr))
#define Curl_unicodefree(ptr) \
- do {if((ptr)) {free((ptr)); (ptr) = NULL;}} WHILE_FALSE
+ do {if((ptr)) {free((ptr)); (ptr) = NULL;}} while(0)
typedef union {
unsigned short *tchar_ptr;
@@ -76,7 +76,7 @@ typedef union {
#define Curl_convert_UTF8_to_tchar(ptr) (ptr)
#define Curl_convert_tchar_to_UTF8(ptr) (ptr)
#define Curl_unicodefree(ptr) \
- do {(ptr) = NULL;} WHILE_FALSE
+ do {(ptr) = NULL;} while(0)
typedef union {
char *tchar_ptr;
diff --git a/lib/curl_setup.h b/lib/curl_setup.h
index b4ba92931..cc36e28ec 100644
--- a/lib/curl_setup.h
+++ b/lib/curl_setup.h
@@ -27,6 +27,14 @@
#endif
/*
+ * Disable Visual Studio warnings:
+ * 4127 "conditional expression is constant"
+ */
+#ifdef _MSC_VER
+#pragma warning(disable:4127)
+#endif
+
+/*
* Define WIN32 when build target is Win32 API
*/
@@ -714,7 +722,7 @@ int netware_init(void);
*/
#ifndef Curl_nop_stmt
-# define Curl_nop_stmt do { } WHILE_FALSE
+# define Curl_nop_stmt do { } while(0)
#endif
/*
diff --git a/lib/curl_setup_once.h b/lib/curl_setup_once.h
index 413ccea91..9d504cb6e 100644
--- a/lib/curl_setup_once.h
+++ b/lib/curl_setup_once.h
@@ -330,27 +330,6 @@ struct timeval {
#include "curl_ctype.h"
/*
- * Macro WHILE_FALSE may be used to build single-iteration do-while loops,
- * avoiding compiler warnings. Mostly intended for other macro definitions.
- */
-
-#define WHILE_FALSE while(0)
-
-#if defined(_MSC_VER) && !defined(__POCC__)
-# undef WHILE_FALSE
-# if (_MSC_VER < 1500)
-# define WHILE_FALSE while(1, 0)
-# else
-# define WHILE_FALSE \
-__pragma(warning(push)) \
-__pragma(warning(disable:4127)) \
-while(0) \
-__pragma(warning(pop))
-# endif
-#endif
-
-
-/*
* Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
*/
@@ -387,7 +366,7 @@ typedef int sig_atomic_t;
#ifdef DEBUGBUILD
#define DEBUGF(x) x
#else
-#define DEBUGF(x) do { } WHILE_FALSE
+#define DEBUGF(x) do { } while(0)
#endif
@@ -398,7 +377,7 @@ typedef int sig_atomic_t;
#if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
#define DEBUGASSERT(x) assert(x)
#else
-#define DEBUGASSERT(x) do { } WHILE_FALSE
+#define DEBUGASSERT(x) do { } while(0)
#endif
diff --git a/lib/doh.c b/lib/doh.c
index 1588a7f32..c8735a648 100644
--- a/lib/doh.c
+++ b/lib/doh.c
@@ -218,7 +218,7 @@ do { \
result = curl_easy_setopt(doh, x, y); \
if(result) \
goto error; \
-} WHILE_FALSE
+} while(0)
static CURLcode dohprobe(struct Curl_easy *data,
struct dnsprobe *p, DNStype dnstype,
diff --git a/lib/http2.c b/lib/http2.c
index 6315fc401..b741aed48 100644
--- a/lib/http2.c
+++ b/lib/http2.c
@@ -68,7 +68,7 @@
#ifdef DEBUG_HTTP2
#define H2BUGF(x) x
#else
-#define H2BUGF(x) do { } WHILE_FALSE
+#define H2BUGF(x) do { } while(0)
#endif
diff --git a/lib/ldap.c b/lib/ldap.c
index af3d61c57..771edb4e9 100644
--- a/lib/ldap.c
+++ b/lib/ldap.c
@@ -112,7 +112,7 @@ static void _ldap_free_urldesc(LDAPURLDesc *ludp);
#define LDAP_TRACE(x) do { \
_ldap_trace("%u: ", __LINE__); \
_ldap_trace x; \
- } WHILE_FALSE
+ } while(0)
static void _ldap_trace(const char *fmt, ...);
#else
diff --git a/lib/memdebug.h b/lib/memdebug.h
index 5236f60fa..7ca442626 100644
--- a/lib/memdebug.h
+++ b/lib/memdebug.h
@@ -169,6 +169,6 @@ CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
*/
#define Curl_safefree(ptr) \
- do { free((ptr)); (ptr) = NULL;} WHILE_FALSE
+ do { free((ptr)); (ptr) = NULL;} while(0)
#endif /* HEADER_CURL_MEMDEBUG_H */
diff --git a/lib/mprintf.c b/lib/mprintf.c
index 4234e1bf4..bc0091351 100644
--- a/lib/mprintf.c
+++ b/lib/mprintf.c
@@ -104,7 +104,7 @@ static const char upper_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
done++; \
else \
return done; /* return immediately on failure */ \
- } WHILE_FALSE
+ } while(0)
/* Data type to read from the arglist */
typedef enum {
diff --git a/lib/select.h b/lib/select.h
index f5652a74f..687ab164c 100644
--- a/lib/select.h
+++ b/lib/select.h
@@ -109,7 +109,7 @@ int tpf_select_libcurl(int maxfds, fd_set* reads, fd_set* writes,
SET_SOCKERRNO(EINVAL); \
return -1; \
} \
-} WHILE_FALSE
+} while(0)
#endif
#endif /* HEADER_CURL_SELECT_H */
diff --git a/lib/sendf.c b/lib/sendf.c
index 000fbb164..6c38b04b2 100644
--- a/lib/sendf.c
+++ b/lib/sendf.c
@@ -224,7 +224,7 @@ bool Curl_recv_has_postponed_data(struct connectdata *conn, int sockindex)
(void)sockindex;
return false;
}
-#define pre_receive_plain(c,n) do {} WHILE_FALSE
+#define pre_receive_plain(c,n) do {} while(0)
#define get_pre_recved(c,n,b,l) 0
#endif /* ! USE_RECV_BEFORE_SEND_WORKAROUND */
diff --git a/lib/sha256.c b/lib/sha256.c
index b467ee558..bcaaeae30 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -58,7 +58,7 @@ do { \
(a)[1] = (unsigned char)((((unsigned long) (val)) >> 16) & 0xff); \
(a)[2] = (unsigned char)((((unsigned long) (val)) >> 8) & 0xff); \
(a)[3] = (unsigned char)(((unsigned long) (val)) & 0xff); \
-} WHILE_FALSE;
+} while(0)
#ifdef HAVE_LONGLONG
#define WPA_PUT_BE64(a, val) \
@@ -71,7 +71,7 @@ do { \
(a)[5] = (unsigned char)(((unsigned long long)(val)) >> 16); \
(a)[6] = (unsigned char)(((unsigned long long)(val)) >> 8); \
(a)[7] = (unsigned char)(((unsigned long long)(val)) & 0xff); \
-} WHILE_FALSE;
+} while(0)
#else
#define WPA_PUT_BE64(a, val) \
do { \
diff --git a/lib/telnet.c b/lib/telnet.c
index 955255c36..4bf4c652c 100644
--- a/lib/telnet.c
+++ b/lib/telnet.c
@@ -69,12 +69,12 @@
do { \
x->subend = x->subpointer; \
CURL_SB_CLEAR(x); \
- } WHILE_FALSE
+ } while(0)
#define CURL_SB_ACCUM(x,c) \
do { \
if(x->subpointer < (x->subbuffer + sizeof(x->subbuffer))) \
*x->subpointer++ = (c); \
- } WHILE_FALSE
+ } while(0)
#define CURL_SB_GET(x) ((*x->subpointer++)&0xff)
#define CURL_SB_LEN(x) (x->subend - x->subpointer)
diff --git a/lib/transfer.c b/lib/transfer.c
index f16e29bdb..ead8b36db 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -1177,7 +1177,7 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
}
- } WHILE_FALSE; /* just to break out from! */
+ } while(0); /* just to break out from! */
return CURLE_OK;
}
diff --git a/lib/url.c b/lib/url.c
index 99a8b1359..1af9f90e0 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -674,7 +674,7 @@ static void conn_reset_all_postponed_data(struct connectdata *conn)
}
#else /* ! USE_RECV_BEFORE_SEND_WORKAROUND */
/* Use "do-nothing" macro instead of function when workaround not used */
-#define conn_reset_all_postponed_data(c) do {} WHILE_FALSE
+#define conn_reset_all_postponed_data(c) do {} while(0)
#endif /* ! USE_RECV_BEFORE_SEND_WORKAROUND */
diff --git a/lib/vquic/ngtcp2.c b/lib/vquic/ngtcp2.c
index 7d8b98e90..c39dba23a 100644
--- a/lib/vquic/ngtcp2.c
+++ b/lib/vquic/ngtcp2.c
@@ -49,7 +49,7 @@
#ifdef DEBUG_HTTP3
#define H3BUGF(x) x
#else
-#define H3BUGF(x) do { } WHILE_FALSE
+#define H3BUGF(x) do { } while(0)
#endif
/*
diff --git a/lib/vquic/quiche.c b/lib/vquic/quiche.c
index b2c98d255..e2f43237f 100644
--- a/lib/vquic/quiche.c
+++ b/lib/vquic/quiche.c
@@ -45,7 +45,7 @@
#ifdef DEBUG_HTTP3
#define H3BUGF(x) x
#else
-#define H3BUGF(x) do { } WHILE_FALSE
+#define H3BUGF(x) do { } while(0)
#endif
#define QUIC_MAX_STREAMS (256*1024)
diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c
index ef8745246..070879d94 100644
--- a/lib/vssh/libssh.c
+++ b/lib/vssh/libssh.c
@@ -98,7 +98,7 @@
/* A recent macro provided by libssh. Or make our own. */
#ifndef SSH_STRING_FREE_CHAR
#define SSH_STRING_FREE_CHAR(x) \
- do { if((x) != NULL) { ssh_string_free_char(x); x = NULL; } } WHILE_FALSE
+ do { if((x) != NULL) { ssh_string_free_char(x); x = NULL; } } while(0)
#endif
/* Local functions: */
diff --git a/lib/vtls/nss.c b/lib/vtls/nss.c
index a375f00da..ef51b0d91 100644
--- a/lib/vtls/nss.c
+++ b/lib/vtls/nss.c
@@ -113,7 +113,7 @@ typedef struct {
ptr->type = (_type); \
ptr->pValue = (_val); \
ptr->ulValueLen = (_len); \
-} WHILE_FALSE
+} while(0)
#define CERT_NewTempCertificate __CERT_NewTempCertificate
diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c
index 32d0e449e..7c6854d1f 100644
--- a/lib/vtls/openssl.c
+++ b/lib/vtls/openssl.c
@@ -3077,7 +3077,7 @@ do { \
Curl_ssl_push_certinfo_len(data, _num, _label, ptr, info_len); \
if(1 != BIO_reset(mem)) \
break; \
-} WHILE_FALSE
+} while(0)
static void pubkey_show(struct Curl_easy *data,
BIO *mem,
@@ -3109,7 +3109,7 @@ do { \
if(_type->_name) { \
pubkey_show(data, mem, _num, #_type, #_name, _type->_name); \
} \
-} WHILE_FALSE
+} while(0)
#endif
static int X509V3_ext(struct Curl_easy *data,