From: Trond Norbye Date: Tue, 11 Aug 2009 18:56:12 +0000 (+0200) Subject: Fix problems reported by: -Wsign-conversion from gcc 4.4 on Solaris X-Git-Tag: 0.32~4^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=4801b6fa83529ab4327b1757e2d3a7ab4670ed5b;p=m6w6%2Flibmemcached Fix problems reported by: -Wsign-conversion from gcc 4.4 on Solaris --- diff --git a/clients/memcat.c b/clients/memcat.c index 1c659b78..944afe72 100644 --- a/clients/memcat.c +++ b/clients/memcat.c @@ -110,14 +110,14 @@ void options_parse(int argc, char *argv[]) static struct option long_options[]= { - {"version", no_argument, NULL, OPT_VERSION}, - {"help", no_argument, NULL, OPT_HELP}, - {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, - {"debug", no_argument, &opt_verbose, OPT_DEBUG}, - {"servers", required_argument, NULL, OPT_SERVERS}, - {"flag", no_argument, &opt_displayflag, OPT_FLAG}, - {"hash", required_argument, NULL, OPT_HASH}, - {"binary", no_argument, NULL, OPT_BINARY}, + {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, + {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, + {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, + {(OPTIONSTRING)"flag", no_argument, &opt_displayflag, OPT_FLAG}, + {(OPTIONSTRING)"hash", required_argument, NULL, OPT_HASH}, + {(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY}, {0, 0, 0, 0}, }; diff --git a/clients/memcp.c b/clients/memcp.c index 778beaf7..716bfefd 100644 --- a/clients/memcp.c +++ b/clients/memcp.c @@ -165,18 +165,18 @@ void options_parse(int argc, char *argv[]) static struct option long_options[]= { - {"version", no_argument, NULL, OPT_VERSION}, - {"help", no_argument, NULL, OPT_HELP}, - {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, - {"debug", no_argument, &opt_verbose, OPT_DEBUG}, - {"servers", required_argument, NULL, OPT_SERVERS}, - {"flag", required_argument, NULL, OPT_FLAG}, - {"expire", required_argument, NULL, OPT_EXPIRE}, - {"set", no_argument, NULL, OPT_SET}, - {"add", no_argument, NULL, OPT_ADD}, - {"replace", no_argument, NULL, OPT_REPLACE}, - {"hash", required_argument, NULL, OPT_HASH}, - {"binary", no_argument, NULL, OPT_BINARY}, + {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, + {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, + {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, + {(OPTIONSTRING)"flag", required_argument, NULL, OPT_FLAG}, + {(OPTIONSTRING)"expire", required_argument, NULL, OPT_EXPIRE}, + {(OPTIONSTRING)"set", no_argument, NULL, OPT_SET}, + {(OPTIONSTRING)"add", no_argument, NULL, OPT_ADD}, + {(OPTIONSTRING)"replace", no_argument, NULL, OPT_REPLACE}, + {(OPTIONSTRING)"hash", required_argument, NULL, OPT_HASH}, + {(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY}, {0, 0, 0, 0}, }; diff --git a/clients/memdump.c b/clients/memdump.c index 3dc687d8..1a21ab64 100644 --- a/clients/memdump.c +++ b/clients/memdump.c @@ -102,13 +102,13 @@ void options_parse(int argc, char *argv[]) static struct option long_options[]= { - {"version", no_argument, NULL, OPT_VERSION}, - {"help", no_argument, NULL, OPT_HELP}, - {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, - {"debug", no_argument, &opt_verbose, OPT_DEBUG}, - {"servers", required_argument, NULL, OPT_SERVERS}, - {"hash", required_argument, NULL, OPT_HASH}, - {"binary", no_argument, NULL, OPT_BINARY}, + {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, + {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, + {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, + {(OPTIONSTRING)"hash", required_argument, NULL, OPT_HASH}, + {(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY}, {0, 0, 0, 0} }; diff --git a/clients/memerror.c b/clients/memerror.c index b70f8830..fbad55ba 100644 --- a/clients/memerror.c +++ b/clients/memerror.c @@ -43,10 +43,10 @@ void options_parse(int argc, char *argv[]) static struct option long_options[]= { - {"version", no_argument, NULL, OPT_VERSION}, - {"help", no_argument, NULL, OPT_HELP}, - {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, - {"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, + {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, + {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, {0, 0, 0, 0}, }; diff --git a/clients/memflush.c b/clients/memflush.c index 0d2727bf..12034adb 100644 --- a/clients/memflush.c +++ b/clients/memflush.c @@ -74,13 +74,13 @@ void options_parse(int argc, char *argv[]) static struct option long_options[]= { - {"version", no_argument, NULL, OPT_VERSION}, - {"help", no_argument, NULL, OPT_HELP}, - {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, - {"debug", no_argument, &opt_verbose, OPT_DEBUG}, - {"servers", required_argument, NULL, OPT_SERVERS}, - {"expire", required_argument, NULL, OPT_EXPIRE}, - {"binary", no_argument, NULL, OPT_BINARY}, + {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, + {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, + {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, + {(OPTIONSTRING)"expire", required_argument, NULL, OPT_EXPIRE}, + {(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY}, {0, 0, 0, 0}, }; int option_index= 0; diff --git a/clients/memrm.c b/clients/memrm.c index 8ed122d7..203146ef 100644 --- a/clients/memrm.c +++ b/clients/memrm.c @@ -87,14 +87,14 @@ void options_parse(int argc, char *argv[]) static struct option long_options[]= { - {"version", no_argument, NULL, OPT_VERSION}, - {"help", no_argument, NULL, OPT_HELP}, - {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, - {"debug", no_argument, &opt_verbose, OPT_DEBUG}, - {"servers", required_argument, NULL, OPT_SERVERS}, - {"expire", required_argument, NULL, OPT_EXPIRE}, - {"hash", required_argument, NULL, OPT_HASH}, - {"binary", no_argument, NULL, OPT_BINARY}, + {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, + {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, + {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, + {(OPTIONSTRING)"expire", required_argument, NULL, OPT_EXPIRE}, + {(OPTIONSTRING)"hash", required_argument, NULL, OPT_HASH}, + {(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY}, {0, 0, 0, 0}, }; int option_index= 0; diff --git a/clients/memslap.c b/clients/memslap.c index 279be30b..4e3d6813 100644 --- a/clients/memslap.c +++ b/clients/memslap.c @@ -238,21 +238,21 @@ void options_parse(int argc, char *argv[]) static struct option long_options[]= { - {"concurrency", required_argument, NULL, OPT_SLAP_CONCURRENCY}, - {"debug", no_argument, &opt_verbose, OPT_DEBUG}, - {"execute-number", required_argument, NULL, OPT_SLAP_EXECUTE_NUMBER}, - {"flag", no_argument, &opt_displayflag, OPT_FLAG}, - {"flush", no_argument, &opt_flush, OPT_FLUSH}, - {"help", no_argument, NULL, OPT_HELP}, - {"initial-load", required_argument, NULL, OPT_SLAP_INITIAL_LOAD}, /* Number to load initially */ - {"non-blocking", no_argument, &opt_non_blocking_io, OPT_SLAP_NON_BLOCK}, - {"servers", required_argument, NULL, OPT_SERVERS}, - {"tcp-nodelay", no_argument, &opt_tcp_nodelay, OPT_SLAP_TCP_NODELAY}, - {"test", required_argument, NULL, OPT_SLAP_TEST}, - {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, - {"version", no_argument, NULL, OPT_VERSION}, - {"binary", no_argument, NULL, OPT_BINARY}, - {"udp", no_argument, NULL, OPT_UDP}, + {(OPTIONSTRING)"concurrency", required_argument, NULL, OPT_SLAP_CONCURRENCY}, + {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {(OPTIONSTRING)"execute-number", required_argument, NULL, OPT_SLAP_EXECUTE_NUMBER}, + {(OPTIONSTRING)"flag", no_argument, &opt_displayflag, OPT_FLAG}, + {(OPTIONSTRING)"flush", no_argument, &opt_flush, OPT_FLUSH}, + {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"initial-load", required_argument, NULL, OPT_SLAP_INITIAL_LOAD}, /* Number to load initially */ + {(OPTIONSTRING)"non-blocking", no_argument, &opt_non_blocking_io, OPT_SLAP_NON_BLOCK}, + {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, + {(OPTIONSTRING)"tcp-nodelay", no_argument, &opt_tcp_nodelay, OPT_SLAP_TCP_NODELAY}, + {(OPTIONSTRING)"test", required_argument, NULL, OPT_SLAP_TEST}, + {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, + {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, + {(OPTIONSTRING)"binary", no_argument, NULL, OPT_BINARY}, + {(OPTIONSTRING)"udp", no_argument, NULL, OPT_UDP}, {0, 0, 0, 0}, }; diff --git a/clients/memstat.c b/clients/memstat.c index 27c34a41..37e18e22 100644 --- a/clients/memstat.c +++ b/clients/memstat.c @@ -35,13 +35,13 @@ static char *analyze_mode= NULL; static struct option long_options[]= { - {"version", no_argument, NULL, OPT_VERSION}, - {"help", no_argument, NULL, OPT_HELP}, - {"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, - {"debug", no_argument, &opt_verbose, OPT_DEBUG}, - {"servers", required_argument, NULL, OPT_SERVERS}, - {"flag", no_argument, &opt_displayflag, OPT_FLAG}, - {"analyze", optional_argument, NULL, OPT_ANALYZE}, + {(OPTIONSTRING)"version", no_argument, NULL, OPT_VERSION}, + {(OPTIONSTRING)"help", no_argument, NULL, OPT_HELP}, + {(OPTIONSTRING)"verbose", no_argument, &opt_verbose, OPT_VERBOSE}, + {(OPTIONSTRING)"debug", no_argument, &opt_verbose, OPT_DEBUG}, + {(OPTIONSTRING)"servers", required_argument, NULL, OPT_SERVERS}, + {(OPTIONSTRING)"flag", no_argument, &opt_displayflag, OPT_FLAG}, + {(OPTIONSTRING)"analyze", optional_argument, NULL, OPT_ANALYZE}, {0, 0, 0, 0}, }; diff --git a/clients/utilities.h b/clients/utilities.h index af670613..7ca92497 100644 --- a/clients/utilities.h +++ b/clients/utilities.h @@ -13,6 +13,15 @@ # endif #endif +#ifdef __sun + /* For some odd reason the option struct on solaris defines the argument + * as char* and not const char* + */ +#define OPTIONSTRING char* +#else +#define OPTIONSTRING const char* +#endif + typedef struct memcached_programs_help_st memcached_programs_help_st; struct memcached_programs_help_st diff --git a/libmemcached/crc.c b/libmemcached/crc.c index 5c586bf0..034ccf1b 100644 --- a/libmemcached/crc.c +++ b/libmemcached/crc.c @@ -80,7 +80,7 @@ uint32_t hash_crc32(const char *key, size_t key_length) uint32_t crc= UINT32_MAX; for (x= 0; x < key_length; x++) - crc= (crc >> 8) ^ crc32tab[(crc ^ (key[x])) & 0xff]; + crc= (crc >> 8) ^ crc32tab[(crc ^ (uint64_t)key[x]) & 0xff]; return ~crc; } diff --git a/libmemcached/memcached_hash.c b/libmemcached/memcached_hash.c index 4956d18e..129d7612 100644 --- a/libmemcached/memcached_hash.c +++ b/libmemcached/memcached_hash.c @@ -40,7 +40,7 @@ uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memca for (x= 0; x < key_length; x++) { temp_hash *= FNV_64_PRIME; - temp_hash ^= key[x]; + temp_hash ^= (uint64_t)key[x]; } hash= (uint32_t)temp_hash; } @@ -50,7 +50,8 @@ uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memca hash= (uint32_t) FNV_64_INIT; for (x= 0; x < key_length; x++) { - hash ^= key[x]; + uint32_t val= (uint32_t)key[x]; + hash ^= val; hash *= (uint32_t) FNV_64_PRIME; } } @@ -60,8 +61,9 @@ uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memca hash= FNV_32_INIT; for (x= 0; x < key_length; x++) { + uint32_t val= (uint32_t)key[x]; hash *= FNV_32_PRIME; - hash ^= key[x]; + hash ^= val; } } break; @@ -70,7 +72,8 @@ uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memca hash= FNV_32_INIT; for (x= 0; x < key_length; x++) { - hash ^= key[x]; + uint32_t val= (uint32_t)key[x]; + hash ^= val; hash *= FNV_32_PRIME; } } @@ -205,7 +208,8 @@ static uint32_t internal_generate_hash(const char *key, size_t key_length) while (key_length--) { - value += (uint32_t) *ptr++; + uint32_t val= (uint32_t) *ptr++; + value += val; value += (value << 10); value ^= (value >> 6); } diff --git a/libmemcached/murmur_hash.c b/libmemcached/murmur_hash.c index b9513440..f1c3267c 100644 --- a/libmemcached/murmur_hash.c +++ b/libmemcached/murmur_hash.c @@ -25,13 +25,13 @@ uint32_t murmur_hash(const char *key, size_t length) */ const unsigned int m= 0x5bd1e995; - const size_t seed= (0xdeadbeef * length); + const uint32_t seed= (0xdeadbeef * (uint32_t)length); const int r= 24; // Initialize the hash to a 'random' value - size_t h= seed ^ length; + uint32_t h= seed ^ (uint32_t)length; // Mix 4 bytes at a time into the hash @@ -56,8 +56,8 @@ uint32_t murmur_hash(const char *key, size_t length) switch(length) { - case 3: h ^= data[2] << 16; - case 2: h ^= data[1] << 8; + case 3: h ^= ((uint32_t)data[2]) << 16; + case 2: h ^= ((uint32_t)data[1]) << 8; case 1: h ^= data[0]; h *= m; default: break; diff --git a/tests/function.c b/tests/function.c index dc373e7b..f4877a95 100644 --- a/tests/function.c +++ b/tests/function.c @@ -2312,6 +2312,7 @@ static test_return user_supplied_bug16(memcached_st *memc) return 0; } +#ifndef __sun /* Check the validity of chinese key*/ static test_return user_supplied_bug17(memcached_st *memc) { @@ -2338,6 +2339,7 @@ static test_return user_supplied_bug17(memcached_st *memc) return 0; } +#endif /* From Andrei on IRC