From: Brian Aker Date: Wed, 10 Apr 2013 06:51:13 +0000 (-0400) Subject: Fix warnings found by cppcheck. X-Git-Tag: 1.0.18~30^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=457e8cd000fa47f002c20af7a8227b7444ab1b42;p=m6w6%2Flibmemcached Fix warnings found by cppcheck. --- diff --git a/clients/memflush.cc b/clients/memflush.cc index 6f9d0c86..8bd0dbf5 100644 --- a/clients/memflush.cc +++ b/clients/memflush.cc @@ -158,7 +158,7 @@ void options_parse(int argc, char *argv[]) opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10); if (errno != 0) { - std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::cerr; + std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::endl; exit(EXIT_FAILURE); } break; diff --git a/clients/memping.cc b/clients/memping.cc index bbbdfda9..180d6a21 100644 --- a/clients/memping.cc +++ b/clients/memping.cc @@ -157,7 +157,7 @@ void options_parse(int argc, char *argv[]) opt_expire= time_t(strtoll(optarg, (char **)NULL, 10)); if (errno != 0) { - std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::cerr; + std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::endl; exit(EXIT_FAILURE); } break; diff --git a/clients/memrm.cc b/clients/memrm.cc index 9b7ca1d0..50ead7a3 100644 --- a/clients/memrm.cc +++ b/clients/memrm.cc @@ -213,7 +213,7 @@ static void options_parse(int argc, char *argv[]) opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10); if (errno != 0) { - std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::cerr; + std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::endl; exit(EXIT_FAILURE); } break; diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index cb88c13b..659d3407 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -186,9 +186,10 @@ static memcached_return_t set_hostinfo(memcached_instance_st* server) assert(server->type != MEMCACHED_CONNECTION_UNIX_SOCKET); server->clear_addrinfo(); - char str_port[MEMCACHED_NI_MAXSERV]; + char str_port[MEMCACHED_NI_MAXSERV]= { 0 }; + errno= 0; int length= snprintf(str_port, MEMCACHED_NI_MAXSERV, "%u", uint32_t(server->port())); - if (length >= MEMCACHED_NI_MAXSERV or length <= 0) + if (length >= MEMCACHED_NI_MAXSERV or length <= 0 or errno != 0) { return memcached_set_error(*server, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, memcached_literal_param("snprintf(NI_MAXSERV)")); @@ -759,6 +760,7 @@ static memcached_return_t _memcached_connect(memcached_instance_st* server, cons case MEMCACHED_CONNECTION_TCP: rc= network_connect(server); +#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT if (LIBMEMCACHED_WITH_SASL_SUPPORT) { if (server->fd != INVALID_SOCKET and server->root->sasl.callbacks) @@ -771,6 +773,7 @@ static memcached_return_t _memcached_connect(memcached_instance_st* server, cons } } } +#endif break; case MEMCACHED_CONNECTION_UNIX_SOCKET: diff --git a/tests/keys.hpp b/tests/keys.hpp index 11b7c061..37f7bafc 100644 --- a/tests/keys.hpp +++ b/tests/keys.hpp @@ -62,18 +62,18 @@ public: key_buffer.resize(padding +1); memset(&key_buffer[0], 'x', padding); +#ifdef HAVE_UUID_UUID_H if (HAVE_UUID_UUID_H) { -#if defined(HAVE_UUID_UUID_H) && HAVE_UUID_UUID_H uuid_t out; uuid_generate(out); uuid_unparse(out, &key_buffer[0]); _keys[x]= strdup(&key_buffer[0]); (_keys[x])[UUID_STRING_MAXLENGTH]= 'x'; -#endif } else // We just use a number and pad the string if UUID is not available +#endif { char int_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1]; int key_length= snprintf(int_buffer, sizeof(int_buffer), "%u", uint32_t(x)); diff --git a/tests/libmemcached-1.0/sasl.cc b/tests/libmemcached-1.0/sasl.cc index 9b398528..d5249b2f 100644 --- a/tests/libmemcached-1.0/sasl.cc +++ b/tests/libmemcached-1.0/sasl.cc @@ -64,6 +64,7 @@ static test_return_t pre_sasl(memcached_st *) */ static test_return_t sasl_auth_test(memcached_st *memc) { +#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT if (LIBMEMCACHED_WITH_SASL_SUPPORT) { test_compare(MEMCACHED_SUCCESS, memcached_set(memc, "foo", 3, "bar", 3, (time_t)0, (uint32_t)0)); @@ -80,6 +81,9 @@ static test_return_t sasl_auth_test(memcached_st *memc) memcached_quit(memc); return TEST_SUCCESS; } +#else + (void)memc; +#endif return TEST_SKIPPED; }