Skip to content
Permalink
Browse files

build: fix Codacy/CppCheck warnings

- remove unused variables
- declare conditionally used variables conditionally
- suppress unused variable warnings in the CMake tests
- remove dead variable stores
- consistently use WIN32 macro to detect Windows

Closes #3739
  • Loading branch information...
MarcelRaad committed Apr 5, 2019
1 parent bb0b101 commit d1b5cf830bfe169745721b21245d2217d2c2453e
@@ -240,6 +240,7 @@ int main()
#ifndef inet_ntoa_r
func_type func;
func = (func_type)inet_ntoa_r;
(void)func;
#endif
return 0;
}
@@ -255,6 +256,7 @@ int main()
#ifndef inet_ntoa_r
func_type func;
func = (func_type)&inet_ntoa_r;
(void)func;
#endif
return 0;
}
@@ -582,7 +584,9 @@ int fun2(int arg1, int arg2) {
int
main() {
int res3 = c99_vmacro3(1, 2, 3);
(void)res3;
int res2 = c99_vmacro2(1, 2);
(void)res2;
return 0;
}
#endif
@@ -114,7 +114,7 @@ typedef void CURLSH;

#ifdef CURL_STATICLIB
# define CURL_EXTERN
#elif defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__) || \
#elif defined(WIN32) || defined(__SYMBIAN32__) || \
(__has_declspec_attribute(dllexport) && \
__has_declspec_attribute(dllimport))
# if defined(BUILDING_LIBCURL)
@@ -68,7 +68,7 @@
#include "progress.h"

# if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \
(defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__))
(defined(WIN32) || defined(__SYMBIAN32__))
# define CARES_STATICLIB
# endif
# include <ares.h>
@@ -123,7 +123,9 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
char ipstr[64];
#ifdef ENABLE_IPV6
if(af == AF_INET6) {
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
unsigned int scopeid = 0;
#endif
unsigned int ifscope = Curl_ipv6_scope(iface->ifa_addr);

if(ifscope != remote_scope) {
@@ -149,9 +151,10 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,

continue;
}
#endif

if(scopeid)
msnprintf(scope, sizeof(scope), "%%%u", scopeid);
msnprintf(scope, sizeof(scope), "%%%u", scopeid);
#endif
}
else
#endif
@@ -124,7 +124,7 @@ static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
CC_MD5_Final(digest, ctx);
}

#elif defined(_WIN32) && !defined(CURL_WINDOWS_APP)
#elif defined(WIN32) && !defined(CURL_WINDOWS_APP)

#include <wincrypt.h>
#include "curl_memory.h"
@@ -66,7 +66,9 @@ struct curltime Curl_now(void)
** in any case the time starting point does not change once that the
** system has started up.
*/
#ifdef HAVE_GETTIMEOFDAY
struct timeval now;
#endif
struct curltime cnow;
struct timespec tsnow;

@@ -31,7 +31,7 @@

#ifdef USE_ARES
# if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \
(defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__))
(defined(WIN32) || defined(__SYMBIAN32__))
# define CARES_STATICLIB
# endif
# include <ares.h>
@@ -1160,7 +1160,6 @@ static CURLcode gskit_connect_common(struct connectdata *conn, int sockindex,
struct Curl_easy *data = conn->data;
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
long timeout_ms;
Qso_OverlappedIO_t cstat;
CURLcode result = CURLE_OK;

*done = connssl->state == ssl_connection_complete;
@@ -389,7 +389,6 @@ Curl_gsk_environment_open(gsk_handle * my_env_handle)

{
struct Curl_gsk_descriptor * p;
gsk_handle h;
int rc;

if(!my_env_handle)
@@ -183,7 +183,6 @@ static void set_features(void)
status = sys_trnlnm("GNV$UNIX_SHELL",
unix_shell_name, sizeof unix_shell_name -1);
if (!$VMS_STATUS_SUCCESS(status)) {
unix_shell_name[0] = 0;
use_unix_settings = 0;
}

@@ -221,7 +221,7 @@ void progressbarinit(struct ProgressData *bar,
struct winsize ts;
if(!ioctl(STDIN_FILENO, TIOCGWINSZ, &ts))
cols = ts.ws_col;
#elif defined(_WIN32)
#elif defined(WIN32)
{
HANDLE stderr_hnd = GetStdHandle(STD_ERROR_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO console_info;
@@ -159,7 +159,7 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
}
}

#ifdef _WIN32
#ifdef WIN32
fhnd = _get_osfhandle(fileno(outs->stream));
if(isatty(fileno(outs->stream)) &&
GetConsoleScreenBufferInfo((HANDLE)fhnd, &console_info)) {
@@ -599,7 +599,6 @@ SANITIZEcode rename_if_reserved_dos_device_name(char **const sanitized,
}
memmove(base + 1, base, blen + 1);
base[0] = '_';
++blen;
}
}
#endif
@@ -237,7 +237,7 @@ static void main_free(struct GlobalConfig *config)
config->last = NULL;
}

#ifdef _WIN32
#ifdef WIN32
/* TerminalSettings for Windows */
static struct TerminalSettings {
HANDLE hStdOut;
@@ -275,7 +275,7 @@ static void configure_terminal(void)

static void restore_terminal(void)
{
#ifdef _WIN32
#ifdef WIN32
/* Restore Console output mode and codepage to whatever they were
* when Curl started */
SetConsoleMode(TerminalSettings.hStdOut, TerminalSettings.dwOutputMode);
@@ -73,7 +73,7 @@
and later. If you're building for an older cat, well, sorry. */
# define COMMON_DIGEST_FOR_OPENSSL
# include <CommonCrypto/CommonDigest.h>
#elif defined(_WIN32)
#elif defined(WIN32)
/* For Windows: If no other crypto library is provided, we fallback
to the hash functions provided within the Microsoft Windows CryptoAPI */
# include <wincrypt.h>
@@ -380,7 +380,7 @@ static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx)
sha256_finish(ctx, digest);
}

#elif defined(_WIN32)
#elif defined(WIN32)

static void win32_crypto_final(struct win32_crypto_hash *ctx,
unsigned char *digest,
@@ -32,14 +32,16 @@ static char g_Data[40 * 1024]; /* POST 40KB */
static int sockopt_callback(void *clientp, curl_socket_t curlfd,
curlsocktype purpose)
{
#if defined(SOL_SOCKET) && defined(SO_SNDBUF)
int sndbufsize = 4 * 1024; /* 4KB send buffer */
(void) clientp;
(void) purpose;
#if defined(SOL_SOCKET) && defined(SO_SNDBUF)
setsockopt(curlfd, SOL_SOCKET, SO_SNDBUF,
(const char *)&sndbufsize, sizeof(sndbufsize));
#else
(void)clientp;
(void)curlfd;
(void)purpose;
#endif
return CURL_SOCKOPT_OK;
}

0 comments on commit d1b5cf8

Please sign in to comment.
You can’t perform that action at this time.