From: Brian Aker Date: Tue, 20 Sep 2011 16:51:44 +0000 (-0700) Subject: Issues fixed for Clang X-Git-Tag: 0.53~12 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d2e05058ca75cce6575dd2ee49e7743200581955;p=awesomized%2Flibmemcached Issues fixed for Clang --- diff --git a/clients/memcapable.cc b/clients/memcapable.cc index 2d82f300..b325413d 100644 --- a/clients/memcapable.cc +++ b/clients/memcapable.cc @@ -1335,7 +1335,10 @@ static enum test_return ascii_get_unknown_value(char **key, char **value, ssize_ verify(strncmp(buffer, "VALUE ", 6) == 0); char *end= strchr(buffer + 6, ' '); verify(end != NULL); - *end= '\0'; + if (end) + { + *end= '\0'; + } *key= strdup(buffer + 6); verify(*key != NULL); char *ptr= end + 1; @@ -1347,9 +1350,9 @@ static enum test_return ascii_get_unknown_value(char **key, char **value, ssize_ *ndata = (ssize_t)strtoul(end, &end, 10); /* size */ verify(ptr != end); verify(end != NULL); - while (*end != '\n' && isspace(*end)) + while (end and *end != '\n' and isspace(*end)) ++end; - verify(*end == '\n'); + verify(end and *end == '\n'); *value= static_cast(malloc((size_t)*ndata)); verify(*value != NULL); @@ -1383,9 +1386,11 @@ static enum test_return ascii_get_value(const char *key, const char *value) verify(ptr != end); verify(val == datasize); verify(end != NULL); - while (*end != '\n' && isspace(*end)) + while (end and *end != '\n' and isspace(*end)) + { ++end; - verify(*end == '\n'); + } + verify(end and *end == '\n'); execute(retry_read(buffer, datasize)); verify(memcmp(buffer, value, datasize) == 0); @@ -1444,9 +1449,11 @@ static enum test_return ascii_gets_value(const char *key, const char *value, verify(val == datasize); verify(end != NULL); - while (*end != '\n' && isspace(*end)) + while (end and *end != '\n' and isspace(*end)) + { ++end; - verify(*end == '\n'); + } + verify(end and *end == '\n'); execute(retry_read(buffer, datasize)); verify(memcmp(buffer, value, datasize) == 0); diff --git a/clients/utilities.cc b/clients/utilities.cc index 4dfc15bb..58717a94 100644 --- a/clients/utilities.cc +++ b/clients/utilities.cc @@ -143,15 +143,25 @@ void process_hash_option(memcached_st *memc, char *opt_hash) set= MEMCACHED_HASH_DEFAULT; /* Just here to solve warning */ if (!strcasecmp(opt_hash, "CRC")) + { set= MEMCACHED_HASH_CRC; + } else if (!strcasecmp(opt_hash, "FNV1_64")) + { set= MEMCACHED_HASH_FNV1_64; + } else if (!strcasecmp(opt_hash, "FNV1A_64")) + { set= MEMCACHED_HASH_FNV1A_64; + } else if (!strcasecmp(opt_hash, "FNV1_32")) + { set= MEMCACHED_HASH_FNV1_32; + } else if (!strcasecmp(opt_hash, "FNV1A_32")) + { set= MEMCACHED_HASH_FNV1A_32; + } else { fprintf(stderr, "hash: type not recognized %s\n", opt_hash); diff --git a/libhashkit/fnv_64.cc b/libhashkit/fnv_64.cc index 842e1d5c..0cfce633 100644 --- a/libhashkit/fnv_64.cc +++ b/libhashkit/fnv_64.cc @@ -39,14 +39,13 @@ #include /* FNV hash'es lifted from Dustin Sallings work */ -static uint64_t FNV_64_INIT= 0xcbf29ce484222325LLU; -static uint64_t FNV_64_PRIME= 0x100000001b3LLU; +static uint64_t FNV_64_INIT= 0xcbf29ce484222325; +static uint64_t FNV_64_PRIME= 0x100000001b3; -uint32_t hashkit_fnv1_64(const char *key, size_t key_length, void *context) +uint32_t hashkit_fnv1_64(const char *key, size_t key_length, void *) { /* Thanks to pierre@demartines.com for the pointer */ uint64_t hash= FNV_64_INIT; - (void)context; for (size_t x= 0; x < key_length; x++) { @@ -57,10 +56,9 @@ uint32_t hashkit_fnv1_64(const char *key, size_t key_length, void *context) return (uint32_t)hash; } -uint32_t hashkit_fnv1a_64(const char *key, size_t key_length, void *context) +uint32_t hashkit_fnv1a_64(const char *key, size_t key_length, void *) { uint32_t hash= (uint32_t) FNV_64_INIT; - (void)context; for (size_t x= 0; x < key_length; x++) { diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index f06d9ca0..9a044faa 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -75,6 +75,11 @@ static memcached_return_t text_incr_decr(memcached_st *ptr, rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); + if (rc == MEMCACHED_SUCCESS) + { + return MEMCACHED_SUCCESS; + } + /* So why recheck responce? Because the protocol is brain dead :) The number returned might end up equaling one of the string diff --git a/libmemcached/delete.cc b/libmemcached/delete.cc index 3f1cde8a..669d8ae1 100644 --- a/libmemcached/delete.cc +++ b/libmemcached/delete.cc @@ -241,7 +241,6 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, if ((rc= memcached_vdo(instance, vector, 3, flush)) != MEMCACHED_SUCCESS) { memcached_io_reset(instance); - rc= (rc == MEMCACHED_SUCCESS) ? MEMCACHED_WRITE_FAILURE : rc; } unlikely (ptr->number_of_replicas > 0) diff --git a/libmemcached/error.cc b/libmemcached/error.cc index b0bdd3f8..afb60645 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -415,8 +415,10 @@ void memcached_error_free(memcached_server_st& self) const char *memcached_last_error_message(memcached_st *memc) { - if (not memc) + if (memc == NULL) + { return memcached_strerror(memc, MEMCACHED_INVALID_ARGUMENTS); + } if (not memc->error_messages) return memcached_strerror(memc, MEMCACHED_SUCCESS); @@ -446,8 +448,10 @@ bool memcached_has_current_error(memcached_server_st& server) memcached_return_t memcached_last_error(memcached_st *memc) { - if (not memc) + if (memc == NULL) + { return MEMCACHED_INVALID_ARGUMENTS; + } if (not memc->error_messages) return MEMCACHED_SUCCESS; @@ -457,19 +461,25 @@ memcached_return_t memcached_last_error(memcached_st *memc) int memcached_last_error_errno(memcached_st *memc) { - if (not memc) + if (memc == NULL) + { return 0; + } if (not memc->error_messages) + { return 0; + } return memc->error_messages->local_errno; } const char *memcached_server_error(memcached_server_instance_st server) { - if (not server) - return memcached_strerror(server->root, MEMCACHED_INVALID_ARGUMENTS); + if (server == NULL) + { + return NULL; + } if (not server->error_messages) return memcached_strerror(server->root, MEMCACHED_SUCCESS); @@ -483,8 +493,10 @@ const char *memcached_server_error(memcached_server_instance_st server) memcached_error_t *memcached_error_copy(const memcached_server_st& server) { - if (not server.error_messages) + if (server.error_messages == NULL) + { return NULL; + } memcached_error_t *error= (memcached_error_t *)libmemcached_malloc(server.root, sizeof(memcached_error_t)); memcpy(error, server.error_messages, sizeof(memcached_error_t)); diff --git a/libmemcached/io.cc b/libmemcached/io.cc index d7268940..e97a6c88 100644 --- a/libmemcached/io.cc +++ b/libmemcached/io.cc @@ -306,7 +306,6 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, return -1; } } - ssize_t sent_length; size_t return_length; char *local_write_ptr= ptr->write_buffer; size_t write_length= ptr->write_buffer_offset; @@ -340,10 +339,10 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, { WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); WATCHPOINT_ASSERT(write_length > 0); - sent_length= 0; if (ptr->type == MEMCACHED_CONNECTION_UDP) increment_udp_message_id(ptr); + ssize_t sent_length= 0; WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); if (with_flush) { @@ -408,7 +407,7 @@ static ssize_t io_flush(memcached_server_write_instance_st ptr, } if (ptr->type == MEMCACHED_CONNECTION_UDP and - (size_t)sent_length != write_length) + size_t(sent_length) != write_length) { memcached_quit_server(ptr, true); *error= memcached_set_error(*ptr, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT); diff --git a/libmemcached/response.cc b/libmemcached/response.cc index 669c633a..adecd6e1 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -201,7 +201,6 @@ static memcached_return_t textual_value_fetch(memcached_server_write_instance_st /* We add two bytes so that we can walk the \r\n */ if (memcached_failed(memcached_string_check(&result->value, value_length +2))) { - value_length= 0; return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } diff --git a/libmemcached/server.cc b/libmemcached/server.cc index ed360ee3..669979ef 100644 --- a/libmemcached/server.cc +++ b/libmemcached/server.cc @@ -195,7 +195,7 @@ memcached_server_st *memcached_server_clone(memcached_server_st *destination, hostname, source->port, source->weight, source->type); - if (not destination) + if (destination) { if (source->error_messages) { diff --git a/libmemcached/stats.cc b/libmemcached/stats.cc index d4d8b33b..515adeeb 100644 --- a/libmemcached/stats.cc +++ b/libmemcached/stats.cc @@ -433,8 +433,7 @@ static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat, string_ptr= end_ptr + 1; for (end_ptr= string_ptr; !(isspace(*end_ptr)); end_ptr++) {}; value= string_ptr; - value[(size_t)(end_ptr-string_ptr)]= 0; - string_ptr= end_ptr + 2; + value[(size_t)(end_ptr -string_ptr)]= 0; if (memc_stat) { unlikely((set_data(memc_stat, key, value)) == MEMCACHED_UNKNOWN_STAT_KEY) diff --git a/libmemcached/virtual_bucket.c b/libmemcached/virtual_bucket.c index 1428fba8..74ec10ef 100644 --- a/libmemcached/virtual_bucket.c +++ b/libmemcached/virtual_bucket.c @@ -71,7 +71,8 @@ memcached_return_t memcached_virtual_bucket_create(memcached_st *self, virtual_bucket->replicas= replicas; self->virtual_bucket= virtual_bucket; - for (uint32_t x=0; x < buckets; x++) + uint32_t x= 0; + for (; x < buckets; x++) { virtual_bucket->buckets[x].master= host_map[x]; if (forward_map) diff --git a/m4/pandora_canonical.m4 b/m4/pandora_canonical.m4 index c7fc9818..f47cbb04 100644 --- a/m4/pandora_canonical.m4 +++ b/m4/pandora_canonical.m4 @@ -298,7 +298,7 @@ AC_DEFUN([PANDORA_CANONICAL_TARGET],[ PANDORA_USE_PIPE - AM_CFLAGS="${AM_CFLAGS} ${CC_WARNINGS} ${CC_PROFILING} ${CC_COVERAGE}" + AM_CFLAGS="-std=c99 ${AM_CFLAGS} ${CC_WARNINGS} ${CC_PROFILING} ${CC_COVERAGE}" AM_CXXFLAGS="${AM_CXXFLAGS} ${CXX_WARNINGS} ${CC_PROFILING} ${CC_COVERAGE}" AC_SUBST([AM_CFLAGS]) diff --git a/m4/pandora_check_cxx_standard.m4 b/m4/pandora_check_cxx_standard.m4 deleted file mode 100644 index a5f0cca3..00000000 --- a/m4/pandora_check_cxx_standard.m4 +++ /dev/null @@ -1,23 +0,0 @@ -dnl Copyright (C) 2009 Sun Microsystems, Inc. -dnl This file is free software; Sun Microsystems, Inc. -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([PANDORA_CHECK_CXX_STANDARD],[ - dnl AC_REQUIRE([AC_CXX_COMPILE_STDCXX_0X]) - AS_IF([test "$GCC" = "yes"], - [AS_IF([test "$ac_cv_cxx_compile_cxx0x_native" = "yes"],[], - [AS_IF([test "$ac_cv_cxx_compile_cxx0x_gxx" = "yes"], - [CXX_STANDARD="-std=gnu++0x"], - [CXX_STANDARD="-std=gnu++98"]) - ]) - ]) - AM_CXXFLAGS="${CXX_STANDARD} ${AM_CXXFLAGS}" - - save_CXXFLAGS="${CXXFLAGS}" - CXXFLAGS="${CXXFLAGS} ${CXX_STANDARD}" - AC_CXX_HEADER_STDCXX_98 - CXXFLAGS="${save_CXXFLAGS}" - - AC_SUBST([CXX_STANDARD]) -]) diff --git a/m4/pandora_compile_stdcxx_0x.m4 b/m4/pandora_compile_stdcxx_0x.m4 deleted file mode 100644 index 4445779a..00000000 --- a/m4/pandora_compile_stdcxx_0x.m4 +++ /dev/null @@ -1,103 +0,0 @@ -# =========================================================================== -# http://autoconf-archive.cryp.to/ac_cxx_compile_stdcxx_0x.html -# =========================================================================== -# -# SYNOPSIS -# -# AC_CXX_COMPILE_STDCXX_0X -# -# DESCRIPTION -# -# Check for baseline language coverage in the compiler for the C++0x -# standard. -# -# LICENSE -# -# Copyright (C) 2008 Benjamin Kosnik -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. - -AC_DEFUN([AC_CXX_COMPILE_STDCXX_0X], [ - AC_CACHE_CHECK(if g++ supports C++0x features without additional flags, - ac_cv_cxx_compile_cxx0x_native, - [AC_LANG_SAVE - AC_LANG_CPLUSPLUS - AC_TRY_COMPILE([ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = c;],, - ac_cv_cxx_compile_cxx0x_native=yes, ac_cv_cxx_compile_cxx0x_native=no) - AC_LANG_RESTORE - ]) - - AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x, - ac_cv_cxx_compile_cxx0x_cxx, - [AC_LANG_SAVE - AC_LANG_CPLUSPLUS - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -std=c++0x" - AC_TRY_COMPILE([ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = c;],, - ac_cv_cxx_compile_cxx0x_cxx=yes, ac_cv_cxx_compile_cxx0x_cxx=no) - CXXFLAGS="$ac_save_CXXFLAGS" - AC_LANG_RESTORE - ]) - - AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x, - ac_cv_cxx_compile_cxx0x_gxx, - [AC_LANG_SAVE - AC_LANG_CPLUSPLUS - ac_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS -std=gnu++0x" - AC_TRY_COMPILE([ - template - struct check - { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); - }; - - typedef check> right_angle_brackets; - - int a; - decltype(a) b; - - typedef check check_type; - check_type c; - check_type&& cr = c;],, - ac_cv_cxx_compile_cxx0x_gxx=yes, ac_cv_cxx_compile_cxx0x_gxx=no) - CXXFLAGS="$ac_save_CXXFLAGS" - AC_LANG_RESTORE - ]) - - if test "$ac_cv_cxx_compile_cxx0x_native" = yes || - test "$ac_cv_cxx_compile_cxx0x_cxx" = yes || - test "$ac_cv_cxx_compile_cxx0x_gxx" = yes; then - AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ]) - fi -]) diff --git a/m4/pandora_optimize.m4 b/m4/pandora_optimize.m4 index b0fd5ad0..05154ed4 100644 --- a/m4/pandora_optimize.m4 +++ b/m4/pandora_optimize.m4 @@ -18,10 +18,6 @@ AC_DEFUN([PANDORA_OPTIMIZE],[ ;; esac - dnl Once we can use a modern autoconf, we can replace the std=gnu99 here - dnl with using AC_CC_STD_C99 above - CC="${CC} -std=gnu99" - AM_CPPFLAGS="-g ${AM_CPPFLAGS}" DEBUG_CFLAGS="-O0" diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index 965b5ec2..dd46c82f 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -572,9 +572,11 @@ static test_return_t cas2_test(memcached_st *memc) test_compare(MEMCACHED_SUCCESS, rc); } - rc= memcached_mget(memc, keys, key_length, 3); + test_compare(MEMCACHED_SUCCESS, + memcached_mget(memc, keys, key_length, 3)); results= memcached_result_create(memc, &results_obj); + test_true(results); results= memcached_fetch_result(memc, &results_obj, &rc); test_true(results); @@ -617,9 +619,11 @@ static test_return_t cas_test(memcached_st *memc) (time_t)0, (uint32_t)0); test_compare(MEMCACHED_SUCCESS, rc); - rc= memcached_mget(memc, keys, keylengths, 1); + test_compare(MEMCACHED_SUCCESS, + memcached_mget(memc, keys, keylengths, 1)); results= memcached_result_create(memc, &results_obj); + test_true(results); results= memcached_fetch_result(memc, &results_obj, &rc); test_true(results); @@ -840,7 +844,7 @@ static test_return_t bad_key_test(memcached_st *memc) /* All keys are valid in the binary protocol (except for length) */ if (not memcached_behavior_get(memc_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) { - query_id= memcached_query_id(memc_clone); + uint64_t before_query_id= memcached_query_id(memc_clone); { size_t string_length; char *string= memcached_get(memc_clone, key, strlen(key), @@ -849,6 +853,7 @@ static test_return_t bad_key_test(memcached_st *memc) test_zero(string_length); test_false(string); } + test_compare(before_query_id, memcached_query_id(memc_clone) +1); query_id= memcached_query_id(memc_clone); test_compare(MEMCACHED_SUCCESS, @@ -1263,6 +1268,7 @@ static test_return_t mget_end(memcached_st *memc) // this should indicate end string= memcached_fetch(memc, key, &key_length, &string_length, &flags, &rc); test_compare(MEMCACHED_END, rc); + test_null(string); // now get just one rc= memcached_mget(memc, keys, lengths, 1); @@ -1279,6 +1285,7 @@ static test_return_t mget_end(memcached_st *memc) // this should indicate end string= memcached_fetch(memc, key, &key_length, &string_length, &flags, &rc); test_compare(MEMCACHED_END, rc); + test_null(string); return TEST_SUCCESS; } @@ -3304,6 +3311,7 @@ static test_return_t mget_read_result(memcached_st *memc) { memcached_result_st results_obj; memcached_result_st *results= memcached_result_create(memc, &results_obj); + test_true(results); memcached_return_t rc; while ((results= memcached_fetch_result(memc, &results_obj, &rc))) @@ -3374,6 +3382,8 @@ static test_return_t mget_read_partial_result(memcached_st *memc) { memcached_result_st results_obj; memcached_result_st *results= memcached_result_create(memc, &results_obj); + test_true(results); + test_false(memcached_is_allocated(results)); memcached_return_t rc; while ((results= memcached_fetch_result(memc, &results_obj, &rc))) @@ -3733,6 +3743,7 @@ static test_return_t selection_of_namespace_tests(memcached_st *memc) /* Make sure be default none exists */ value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc); + test_null(value); test_compare_got(MEMCACHED_FAILURE, rc, memcached_strerror(NULL, rc)); /* Test a clean set */ @@ -3804,6 +3815,7 @@ static test_return_t set_namespace(memcached_st *memc) /* Make sure be default none exists */ value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc); + test_null(value); test_compare_got(MEMCACHED_FAILURE, rc, memcached_strerror(NULL, rc)); /* Test a clean set */