From 398f48445cacf12679248142f0c86d3a0d6caab6 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 30 Jan 2020 09:27:29 +0100 Subject: [PATCH] cppcheck: fix warnings --- .cppcheck/.gitignore | 2 + .gitignore | 1 - clients/memaslap.c | 6 +-- clients/memcapable.cc | 3 +- clients/ms_atomic.h | 32 ++++++------ clients/ms_conn.c | 3 +- clients/ms_conn.h | 2 +- libhashkit/jenkins.cc | 48 +++++++++++------ libhashkit/murmur3.cc | 96 +++++++++++++++++++++------------- libmemcached-1.0/memcached.hpp | 4 +- libmemcached.cppcheck | 29 ++++++++++ libmemcached/csl/context.cc | 6 +-- libmemcached/delete.cc | 1 - libmemcached/error.cc | 4 +- libmemcached/io.cc | 4 +- libmemcached/response.cc | 2 +- libmemcached/touch.cc | 1 - util/instance.cc | 2 +- 18 files changed, 158 insertions(+), 88 deletions(-) create mode 100644 .cppcheck/.gitignore create mode 100644 libmemcached.cppcheck diff --git a/.cppcheck/.gitignore b/.cppcheck/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/.cppcheck/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/.gitignore b/.gitignore index a8ea2a6d..25348f7a 100644 --- a/.gitignore +++ b/.gitignore @@ -170,4 +170,3 @@ tests/testudp tests/var/ tmp_chroot unittests/unittests -.idea/ diff --git a/clients/memaslap.c b/clients/memaslap.c index 02907945..dc411350 100644 --- a/clients/memaslap.c +++ b/clients/memaslap.c @@ -349,15 +349,15 @@ static int64_t ms_parse_time() case 'd': case 'D': ret*= 24; - + /* fall through */ case 'h': case 'H': ret*= 60; - + /* fall through */ case 'm': case 'M': ret*= 60; - + /* fall through */ case 's': case 'S': break; diff --git a/clients/memcapable.cc b/clients/memcapable.cc index 31c2fc54..c52b3c46 100644 --- a/clients/memcapable.cc +++ b/clients/memcapable.cc @@ -37,7 +37,7 @@ #include #include "libmemcached/socket.hpp" -#include "libmemcached/memcached/protocol_binary.h" +#include "libmemcachedprotocol-0.0/binary.h" #include "libmemcached/byteorder.h" #include "clients/utilities.h" @@ -536,6 +536,7 @@ static enum test_return do_validate_response_header(response *rsp, case PROTOCOL_BINARY_CMD_REPLACEQ: case PROTOCOL_BINARY_CMD_SETQ: verify("Quiet command shouldn't return on success" == NULL); + /* fall through */ default: break; } diff --git a/clients/ms_atomic.h b/clients/ms_atomic.h index 0b05bcec..7559044a 100644 --- a/clients/ms_atomic.h +++ b/clients/ms_atomic.h @@ -47,23 +47,23 @@ # define atomic_dec_size_nv(X) __sync_fetch_and_sub((X), 1) #else #warning "Atomic operators not found so memslap will not work correctly" -# define atomic_add_8(X, Y) -# define atomic_add_16(X, Y) -# define atomic_add_32(X, Y) -# define atomic_add_size(X, Y) -# define atomic_dec_8(X) -# define atomic_dec_16(X) -# define atomic_dec_32(X) -# define atomic_dec_size(X) +# define atomic_add_8(X, Y) 0 +# define atomic_add_16(X, Y) 0 +# define atomic_add_32(X, Y) 0 +# define atomic_add_size(X, Y) 0 +# define atomic_dec_8(X) 0 +# define atomic_dec_16(X) 0 +# define atomic_dec_32(X) 0 +# define atomic_dec_size(X) 0 /* The same as above, but these return the new value instead of void */ -# define atomic_add_8_nv(X, Y) -# define atomic_add_16_nv(X, Y) -# define atomic_add_32_nv(X, Y) -# define atomic_add_size_nv(X, Y) -# define atomic_dec_8_nv(X) -# define atomic_dec_16_nv(X) -# define atomic_dec_32_nv(X) -# define atomic_dec_size_nv(X) +# define atomic_add_8_nv(X, Y) 0 +# define atomic_add_16_nv(X, Y) 0 +# define atomic_add_32_nv(X, Y) 0 +# define atomic_add_size_nv(X, Y) 0 +# define atomic_dec_8_nv(X) 0 +# define atomic_dec_16_nv(X) 0 +# define atomic_dec_32_nv(X) 0 +# define atomic_dec_size_nv(X) 0 #endif /* defined(__SUNPRO_C) */ #endif /* CLIENTS_MS_ATOMIC_H */ diff --git a/clients/ms_conn.c b/clients/ms_conn.c index 2afc9fa1..85e84739 100644 --- a/clients/ms_conn.c +++ b/clients/ms_conn.c @@ -1184,6 +1184,7 @@ static int ms_ascii_process_line(ms_conn_t *c, char *command) case 'O': /* OK */ c->currcmd.retstat= MCD_SUCCESS; + break; case 'S': /* STORED STATS SERVER_ERROR */ if (buffer[2] == 'A') /* STORED STATS */ @@ -2344,7 +2345,7 @@ static void ms_conn_shrink(ms_conn_t *c) && (c->rudpbytes + UDP_MAX_PAYLOAD_SIZE < UDP_DATA_BUFFER_SIZE)) { char *new_rbuf= (char *)realloc(c->rudpbuf, (size_t)c->rudpsize * 2); - if (! new_rbuf) + if (new_rbuf) { c->rudpbuf= new_rbuf; c->rudpsize= UDP_DATA_BUFFER_SIZE; diff --git a/clients/ms_conn.h b/clients/ms_conn.h index b915888d..943965ca 100644 --- a/clients/ms_conn.h +++ b/clients/ms_conn.h @@ -17,7 +17,7 @@ #include #include "ms_task.h" -#include +#include #ifdef __cplusplus extern "C" { diff --git a/libhashkit/jenkins.cc b/libhashkit/jenkins.cc index 2197c4cc..3c6558a4 100644 --- a/libhashkit/jenkins.cc +++ b/libhashkit/jenkins.cc @@ -173,23 +173,28 @@ uint32_t hashkit_jenkins(const char *key, size_t length, void *) b+=k[2]+(((uint32_t)k[3])<<16); a+=k[0]+(((uint32_t)k[1])<<16); break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 11: c+=((uint32_t)k8[10])<<16; + /* fall through */ case 10: c+=k[4]; b+=k[2]+(((uint32_t)k[3])<<16); a+=k[0]+(((uint32_t)k[1])<<16); break; - case 9 : c+=k8[8]; /* fall through */ + case 9 : c+=k8[8]; + /* fall through */ case 8 : b+=k[2]+(((uint32_t)k[3])<<16); a+=k[0]+(((uint32_t)k[1])<<16); break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 7 : b+=((uint32_t)k8[6])<<16; + /* fall through */ case 6 : b+=k[2]; a+=k[0]+(((uint32_t)k[1])<<16); break; - case 5 : b+=k8[4]; /* fall through */ + case 5 : b+=k8[4]; + /* fall through */ case 4 : a+=k[0]+(((uint32_t)k[1])<<16); break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 3 : a+=((uint32_t)k8[2])<<16; + /* fall through */ case 2 : a+=k[0]; break; case 1 : a+=k8[0]; @@ -227,17 +232,28 @@ uint32_t hashkit_jenkins(const char *key, size_t length, void *) /*-------------------------------- last block: affect all 32 bits of (c) */ switch(length) /* all the case statements fall through */ { - case 12: c+=((uint32_t)k[11])<<24; /* fall through */ - case 11: c+=((uint32_t)k[10])<<16; /* fall through */ - case 10: c+=((uint32_t)k[9])<<8; /* fall through */ - case 9 : c+=k[8]; /* fall through */ - case 8 : b+=((uint32_t)k[7])<<24; /* fall through */ - case 7 : b+=((uint32_t)k[6])<<16; /* fall through */ - case 6 : b+=((uint32_t)k[5])<<8; /* fall through */ - case 5 : b+=k[4]; /* fall through */ - case 4 : a+=((uint32_t)k[3])<<24; /* fall through */ - case 3 : a+=((uint32_t)k[2])<<16; /* fall through */ - case 2 : a+=((uint32_t)k[1])<<8; /* fall through */ + case 12: c+=((uint32_t)k[11])<<24; + /* fall through */ + case 11: c+=((uint32_t)k[10])<<16; + /* fall through */ + case 10: c+=((uint32_t)k[9])<<8; + /* fall through */ + case 9 : c+=k[8]; + /* fall through */ + case 8 : b+=((uint32_t)k[7])<<24; + /* fall through */ + case 7 : b+=((uint32_t)k[6])<<16; + /* fall through */ + case 6 : b+=((uint32_t)k[5])<<8; + /* fall through */ + case 5 : b+=k[4]; + /* fall through */ + case 4 : a+=((uint32_t)k[3])<<24; + /* fall through */ + case 3 : a+=((uint32_t)k[2])<<16; + /* fall through */ + case 2 : a+=((uint32_t)k[1])<<8; + /* fall through */ case 1 : a+=k[0]; break; case 0 : return c; diff --git a/libhashkit/murmur3.cc b/libhashkit/murmur3.cc index 8d86cfd8..254b5090 100644 --- a/libhashkit/murmur3.cc +++ b/libhashkit/murmur3.cc @@ -115,8 +115,10 @@ void MurmurHash3_x86_32 ( const void * key, int len, switch(len & 3) { - case 3: k1 ^= tail[2] << 16; /* fall through */ - case 2: k1 ^= tail[1] << 8; /* fall through */ + case 3: k1 ^= tail[2] << 16; + /* fall through */ + case 2: k1 ^= tail[1] << 8; + /* fall through */ case 1: k1 ^= tail[0]; k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1; }; @@ -191,27 +193,38 @@ void MurmurHash3_x86_128 ( const void * key, const int len, switch(len & 15) { - case 15: k4 ^= tail[14] << 16; /* fall through */ - case 14: k4 ^= tail[13] << 8; /* fall through */ + case 15: k4 ^= tail[14] << 16; + /* fall through */ + case 14: k4 ^= tail[13] << 8; + /* fall through */ case 13: k4 ^= tail[12] << 0; k4 *= c4; k4 = ROTL32(k4,18); k4 *= c1; h4 ^= k4; - /* fall through */ - case 12: k3 ^= tail[11] << 24; /* fall through */ - case 11: k3 ^= tail[10] << 16; /* fall through */ - case 10: k3 ^= tail[ 9] << 8; /* fall through */ - case 9: k3 ^= tail[ 8] << 0; /* fall through */ + /* fall through */ + case 12: k3 ^= tail[11] << 24; + /* fall through */ + case 11: k3 ^= tail[10] << 16; + /* fall through */ + case 10: k3 ^= tail[ 9] << 8; + /* fall through */ + case 9: k3 ^= tail[ 8] << 0; k3 *= c3; k3 = ROTL32(k3,17); k3 *= c4; h3 ^= k3; - /* fall through */ - case 8: k2 ^= tail[ 7] << 24; /* fall through */ - case 7: k2 ^= tail[ 6] << 16; /* fall through */ - case 6: k2 ^= tail[ 5] << 8; /* fall through */ - case 5: k2 ^= tail[ 4] << 0; /* fall through */ + /* fall through */ + case 8: k2 ^= tail[ 7] << 24; + /* fall through */ + case 7: k2 ^= tail[ 6] << 16; + /* fall through */ + case 6: k2 ^= tail[ 5] << 8; + /* fall through */ + case 5: k2 ^= tail[ 4] << 0; k2 *= c2; k2 = ROTL32(k2,16); k2 *= c3; h2 ^= k2; - /* fall through */ - case 4: k1 ^= tail[ 3] << 24; /* fall through */ - case 3: k1 ^= tail[ 2] << 16; /* fall through */ - case 2: k1 ^= tail[ 1] << 8; /* fall through */ - case 1: k1 ^= tail[ 0] << 0; /* fall through */ + /* fall through */ + case 4: k1 ^= tail[ 3] << 24; + /* fall through */ + case 3: k1 ^= tail[ 2] << 16; + /* fall through */ + case 2: k1 ^= tail[ 1] << 8; + /* fall through */ + case 1: k1 ^= tail[ 0] << 0; k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1; }; @@ -281,23 +294,36 @@ void MurmurHash3_x64_128 ( const void * key, const int len, switch(len & 15) { - case 15: k2 ^= (uint64_t)(tail[14]) << 48; /* fall through */ - case 14: k2 ^= (uint64_t)(tail[13]) << 40; /* fall through */ - case 13: k2 ^= (uint64_t)(tail[12]) << 32; /* fall through */ - case 12: k2 ^= (uint64_t)(tail[11]) << 24; /* fall through */ - case 11: k2 ^= (uint64_t)(tail[10]) << 16; /* fall through */ - case 10: k2 ^= (uint64_t)(tail[ 9]) << 8; /* fall through */ - case 9: k2 ^= (uint64_t)(tail[ 8]) << 0; /* fall through */ + case 15: k2 ^= (uint64_t)(tail[14]) << 48; + /* fall through */ + case 14: k2 ^= (uint64_t)(tail[13]) << 40; + /* fall through */ + case 13: k2 ^= (uint64_t)(tail[12]) << 32; + /* fall through */ + case 12: k2 ^= (uint64_t)(tail[11]) << 24; + /* fall through */ + case 11: k2 ^= (uint64_t)(tail[10]) << 16; + /* fall through */ + case 10: k2 ^= (uint64_t)(tail[ 9]) << 8; + /* fall through */ + case 9: k2 ^= (uint64_t)(tail[ 8]) << 0; k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2; - /* fall through */ - case 8: k1 ^= (uint64_t)(tail[ 7]) << 56; /* fall through */ - case 7: k1 ^= (uint64_t)(tail[ 6]) << 48; /* fall through */ - case 6: k1 ^= (uint64_t)(tail[ 5]) << 40; /* fall through */ - case 5: k1 ^= (uint64_t)(tail[ 4]) << 32; /* fall through */ - case 4: k1 ^= (uint64_t)(tail[ 3]) << 24; /* fall through */ - case 3: k1 ^= (uint64_t)(tail[ 2]) << 16; /* fall through */ - case 2: k1 ^= (uint64_t)(tail[ 1]) << 8; /* fall through */ - case 1: k1 ^= (uint64_t)(tail[ 0]) << 0; /* fall through */ + /* fall through */ + case 8: k1 ^= (uint64_t)(tail[ 7]) << 56; + /* fall through */ + case 7: k1 ^= (uint64_t)(tail[ 6]) << 48; + /* fall through */ + case 6: k1 ^= (uint64_t)(tail[ 5]) << 40; + /* fall through */ + case 5: k1 ^= (uint64_t)(tail[ 4]) << 32; + /* fall through */ + case 4: k1 ^= (uint64_t)(tail[ 3]) << 24; + /* fall through */ + case 3: k1 ^= (uint64_t)(tail[ 2]) << 16; + /* fall through */ + case 2: k1 ^= (uint64_t)(tail[ 1]) << 8; + /* fall through */ + case 1: k1 ^= (uint64_t)(tail[ 0]) << 0; k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1; }; diff --git a/libmemcached-1.0/memcached.hpp b/libmemcached-1.0/memcached.hpp index 9e3051c4..af12f300 100644 --- a/libmemcached-1.0/memcached.hpp +++ b/libmemcached-1.0/memcached.hpp @@ -485,13 +485,11 @@ public: time_t expiration, uint32_t flags) { - bool retval= true; std::map >::const_iterator it= key_value_map.begin(); while (it != key_value_map.end()) { - retval= set(it->first, it->second, expiration, flags); - if (retval == false) + if (!set(it->first, it->second, expiration, flags)) { // We should tell the user what the key that failed was return false; diff --git a/libmemcached.cppcheck b/libmemcached.cppcheck new file mode 100644 index 00000000..2baa38df --- /dev/null +++ b/libmemcached.cppcheck @@ -0,0 +1,29 @@ + + + .cppcheck + native + false + true + false + 10 + + + + + HARD_MALLOC_TEST + + + + + + + + + + + + + + + + diff --git a/libmemcached/csl/context.cc b/libmemcached/csl/context.cc index 16852d5b..44fb4358 100644 --- a/libmemcached/csl/context.cc +++ b/libmemcached/csl/context.cc @@ -67,7 +67,7 @@ void Context::error(const char *error_arg, yytokentype last_token, const char *l return; } - if (error_arg and strcmp(error_arg, "memory exhausted") == 0) + if (strcmp(error_arg, "memory exhausted") == 0) { (void)memcached_set_error(*memc, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, memcached_string_make_from_cstr(error_arg)); return; @@ -75,9 +75,7 @@ void Context::error(const char *error_arg, yytokentype last_token, const char *l // We now test if it is something other then a syntax error, if it we // return a generic message - if (error_arg and strcmp(error_arg, "syntax error") == 0) - { } - else if (error_arg) + if (strcmp(error_arg, "syntax error") != 0) { memcached_set_parser_error(*memc, MEMCACHED_AT, "Error occured during parsing (%s)", error_arg); return; diff --git a/libmemcached/delete.cc b/libmemcached/delete.cc index 9575a957..ef1d8472 100644 --- a/libmemcached/delete.cc +++ b/libmemcached/delete.cc @@ -36,7 +36,6 @@ */ #include -#include memcached_return_t memcached_delete(memcached_st *shell, const char *key, size_t key_length, time_t expiration) diff --git a/libmemcached/error.cc b/libmemcached/error.cc index ced9d7a2..3de8ece5 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -651,7 +651,7 @@ memcached_return_t memcached_server_error_return(const memcached_instance_st * p return MEMCACHED_INVALID_ARGUMENTS; } - if (ptr and ptr->error_messages) + if (ptr->error_messages) { return ptr->error_messages->rc; } @@ -666,7 +666,7 @@ memcached_return_t memcached_instance_error_return(memcached_instance_st* instan return MEMCACHED_INVALID_ARGUMENTS; } - if (instance and instance->error_messages) + if (instance->error_messages) { return instance->error_messages->rc; } diff --git a/libmemcached/io.cc b/libmemcached/io.cc index d2196f67..13c8cf31 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -454,8 +454,10 @@ static memcached_return_t _io_fill(memcached_instance_st* instance) case ENOTCONN: // Programmer Error WATCHPOINT_ASSERT(0); + // fall through case ENOTSOCK: WATCHPOINT_ASSERT(0); + // fall through case EBADF: assert_msg(instance->fd != INVALID_SOCKET, "Programmer error, invalid socket"); /* fall through */ @@ -587,9 +589,9 @@ memcached_return_t memcached_io_slurp(memcached_instance_st* instance) /* fall through */ case ENOTCONN: // Programmer Error - assert(0); case ENOTSOCK: assert(0); + /* fall through */ case EBADF: assert_msg(instance->fd != INVALID_SOCKET, "Invalid socket state"); /* fall through */ diff --git a/libmemcached/response.cc b/libmemcached/response.cc index 554f6dce..3d1e764e 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -534,7 +534,7 @@ static memcached_return_t binary_read_one_response(memcached_instance_st* instan * (only the final NOOP), so we need to increment the counter again. */ memcached_server_response_increment(instance); - /* FALLTHROUGH */ + /* fall through */ case PROTOCOL_BINARY_CMD_GETK: { uint16_t keylen= header.response.keylen; diff --git a/libmemcached/touch.cc b/libmemcached/touch.cc index a1e6d0a1..9e9cbd6e 100644 --- a/libmemcached/touch.cc +++ b/libmemcached/touch.cc @@ -36,7 +36,6 @@ */ #include -#include static memcached_return_t ascii_touch(memcached_instance_st* instance, const char *key, size_t key_length, diff --git a/util/instance.cc b/util/instance.cc index 1b997397..8f5d1738 100644 --- a/util/instance.cc +++ b/util/instance.cc @@ -151,7 +151,7 @@ bool Instance::run() return false; } _addrinfo_next= _addrinfo_next->ai_next; - + /* fall through */ case CONNECT: close_socket(); -- 2.30.2