From: Monty Taylor Date: Mon, 15 Jun 2009 13:03:47 +0000 (+0000) Subject: Fixed -Wconversion warnings. X-Git-Tag: 0.31~14^2~7^2~1^2~2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=15b99ad0b4c2b71bdbeb58580914d442f95d75f0;p=awesomized%2Flibmemcached Fixed -Wconversion warnings. --- diff --git a/clients/execute.c b/clients/execute.c index 490662d3..a0e31ee9 100644 --- a/clients/execute.c +++ b/clients/execute.c @@ -46,7 +46,7 @@ unsigned int execute_get(memcached_st *memc, pairs_st *pairs, unsigned int numbe uint32_t flags; unsigned int fetch_key; - fetch_key= random() % number_of; + fetch_key= (unsigned int)(random() % number_of); value= memcached_get(memc, pairs[fetch_key].key, pairs[fetch_key].key_length, &value_length, &flags, &rc); diff --git a/clients/memcat.c b/clients/memcat.c index 5f5f2cda..1c659b78 100644 --- a/clients/memcat.c +++ b/clients/memcat.c @@ -52,7 +52,8 @@ int main(int argc, char *argv[]) memcached_server_push(memc, servers); memcached_server_list_free(servers); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, opt_binary); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, + (uint64_t)opt_binary); while (optind < argc) { diff --git a/clients/memcp.c b/clients/memcp.c index 1762b601..d6864b1a 100644 --- a/clients/memcp.c +++ b/clients/memcp.c @@ -62,7 +62,8 @@ int main(int argc, char *argv[]) memcached_server_push(memc, servers); memcached_server_list_free(servers); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, opt_binary); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, + (uint64_t)opt_binary); while (optind < argc) { @@ -97,13 +98,13 @@ int main(int argc, char *argv[]) ptr, opt_flags, (unsigned long long)opt_expires); } - if ((file_buffer_ptr= (char *)malloc(sizeof(char) * sbuf.st_size)) == NULL) + if ((file_buffer_ptr= (char *)malloc(sizeof(char) * (size_t)sbuf.st_size)) == NULL) { fprintf(stderr, "malloc: %s\n", strerror(errno)); exit(1); } - if ((read_length= read(fd, file_buffer_ptr, sbuf.st_size)) == -1) + if ((read_length= read(fd, file_buffer_ptr, (size_t)sbuf.st_size)) == -1) { fprintf(stderr, "read: %s\n", strerror(errno)); exit(1); @@ -117,15 +118,15 @@ int main(int argc, char *argv[]) if (opt_method == OPT_ADD) rc= memcached_add(memc, ptr, strlen(ptr), - file_buffer_ptr, sbuf.st_size, + file_buffer_ptr, (size_t)sbuf.st_size, opt_expires, opt_flags); else if (opt_method == OPT_REPLACE) rc= memcached_replace(memc, ptr, strlen(ptr), - file_buffer_ptr, sbuf.st_size, + file_buffer_ptr, (size_t)sbuf.st_size, opt_expires, opt_flags); else rc= memcached_set(memc, ptr, strlen(ptr), - file_buffer_ptr, sbuf.st_size, + file_buffer_ptr, (size_t)sbuf.st_size, opt_expires, opt_flags); if (rc != MEMCACHED_SUCCESS) diff --git a/clients/memdump.c b/clients/memdump.c index dd00d8b3..3dc687d8 100644 --- a/clients/memdump.c +++ b/clients/memdump.c @@ -72,7 +72,8 @@ int main(int argc, char *argv[]) memcached_server_push(memc, servers); memcached_server_list_free(servers); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, opt_binary); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, + (uint64_t)opt_binary); rc= memcached_dump(memc, callbacks, NULL, 1); diff --git a/clients/memflush.c b/clients/memflush.c index abd19ce4..0d2727bf 100644 --- a/clients/memflush.c +++ b/clients/memflush.c @@ -44,7 +44,8 @@ int main(int argc, char *argv[]) servers= memcached_servers_parse(opt_servers); memcached_server_push(memc, servers); memcached_server_list_free(servers); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, opt_binary); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, + (uint64_t) opt_binary); rc = memcached_flush(memc, opt_expire); if (rc != MEMCACHED_SUCCESS) diff --git a/clients/memrm.c b/clients/memrm.c index c4ef1bda..8ed122d7 100644 --- a/clients/memrm.c +++ b/clients/memrm.c @@ -46,7 +46,8 @@ int main(int argc, char *argv[]) servers= memcached_servers_parse(opt_servers); memcached_server_push(memc, servers); memcached_server_list_free(servers); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, opt_binary); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, + (uint64_t) opt_binary); while (optind < argc) { diff --git a/clients/memslap.c b/clients/memslap.c index 5e747b23..279be30b 100644 --- a/clients/memslap.c +++ b/clients/memslap.c @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) memset(&conclusion, 0, sizeof(conclusions_st)); - srandom(time(NULL)); + srandom((unsigned int)time(NULL)); options_parse(argc, argv); if (!opt_servers) @@ -146,13 +146,15 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion) /* We need to set udp behavior before adding servers to the client */ if (opt_udp_io) { - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP, opt_udp_io); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP, + (uint64_t)opt_udp_io); for(x= 0; x < servers[0].count; x++ ) servers[x].type= MEMCACHED_CONNECTION_UDP; } memcached_server_push(memc, servers); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, opt_binary); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, + (uint64_t)opt_binary); if (opt_flush) flush_all(memc); @@ -312,13 +314,13 @@ void options_parse(int argc, char *argv[]) } break; case OPT_SLAP_CONCURRENCY: - opt_concurrency= strtol(optarg, (char **)NULL, 10); + opt_concurrency= (unsigned int)strtoul(optarg, (char **)NULL, 10); break; case OPT_SLAP_EXECUTE_NUMBER: - opt_execute_number= strtol(optarg, (char **)NULL, 10); + opt_execute_number= (unsigned int)strtoul(optarg, (char **)NULL, 10); break; case OPT_SLAP_INITIAL_LOAD: - opt_createial_load= strtol(optarg, (char **)NULL, 10); + opt_createial_load= (unsigned int)strtoul(optarg, (char **)NULL, 10); break; case '?': /* getopt_long already printed an error message. */ diff --git a/clients/utilities.c b/clients/utilities.c index 466c0485..6551684d 100644 --- a/clients/utilities.c +++ b/clients/utilities.c @@ -9,9 +9,9 @@ long int timedif(struct timeval a, struct timeval b) { register int us, s; - us = a.tv_usec - b.tv_usec; + us = (int)(a.tv_usec - b.tv_usec); us /= 1000; - s = a.tv_sec - b.tv_sec; + s = (int)(a.tv_sec - b.tv_sec); s *= 1000; return s + us; } diff --git a/configure.ac b/configure.ac index 422a41d1..46f23555 100644 --- a/configure.ac +++ b/configure.ac @@ -217,9 +217,30 @@ then AS_IF([test "$building_from_bzr" = "yes"], [W_FAIL="-Werror"]) - BASE_WARNINGS="-pedantic -W -Wall -Wextra ${W_FAIL} -Wundef -Wshadow -Wmissing-declarations ${W_STRICT_ALIASING}" - CC_WARNINGS="${BASE_WARNINGS} -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wswitch-default -Wswitch-enum -Wcast-align" - CXX_WARNINGS="${BASE_WARNINGS} -Woverloaded-virtual -Wnon-virtual-dtor -Wctor-dtor-privacy -Wold-style-cast -Weffc++ -Wno-long-long" + BASE_WARNINGS="-pedantic -W -Wall -Wextra ${W_FAIL} -Wundef -Wshadow -Wmissing-declarations ${W_STRICT_ALIASING} -fdiagnostics-show-option" + CC_WARNINGS="${BASE_WARNINGS} -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wswitch-default -Wswitch-enum -Wcast-align -Wconversion" + CXX_WARNINGS="${BASE_WARNINGS} -Woverloaded-virtual -Wnon-virtual-dtor -Wctor-dtor-privacy -Wold-style-cast -Weffc++ -Wno-long-long -Wconversion" + + AC_CACHE_CHECK([whether it is safe to use -Wconversion with htons], + [ac_cv_safe_to_use_Wconversion_], + [save_CFLAGS="$CFLAGS" + CFLAGS="${CC_WARNINGS} ${CFLAGS}" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include + ]],[[ +size_t source_port= 80; +uint16_t x= htons((uint16_t)source_port); + ]])], + [ac_cv_safe_to_use_Wconversion_=yes], + [ac_cv_safe_to_use_Wconversion_=no]) + CFLAGS="$save_CFLAGS"]) + + AS_IF([test "$ac_cv_safe_to_use_Wconversion_" = "no"], + [ + NO_CONVERSION="-Wno-conversion" + ]) AC_CACHE_CHECK([whether it is safe to use -Wlogical-op], @@ -290,6 +311,7 @@ then CXX_WARNINGS="+w +w2 -xwe -xport64 -errtags=yes ${W_FAIL}" fi +AC_SUBST(NO_CONVERSION) AC_SUBST(NO_REDUNDANT_DECLS) AM_CPPFLAGS="-I\$(top_srcdir) -I\$(top_builddir) ${CPPFLAGS}" diff --git a/libmemcached/Makefile.am b/libmemcached/Makefile.am index 1e3224c0..f8b4da29 100644 --- a/libmemcached/Makefile.am +++ b/libmemcached/Makefile.am @@ -30,6 +30,7 @@ endif lib_LTLIBRARIES = libmemcached.la +libmemcached_la_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION} libmemcached_la_SOURCES = crc.c \ memcached.c \ memcached_auto.c \ diff --git a/libmemcached/memcached_auto.c b/libmemcached/memcached_auto.c index 700c4183..2cb810db 100644 --- a/libmemcached/memcached_auto.c +++ b/libmemcached/memcached_auto.c @@ -85,7 +85,7 @@ static memcached_return binary_incr_decr(memcached_st *ptr, uint8_t cmd, request.message.header.request.magic= PROTOCOL_BINARY_REQ; request.message.header.request.opcode= cmd; - request.message.header.request.keylen= htons((uint16_t)key_length); + request.message.header.request.keylen= htons(key_length); request.message.header.request.extlen= 20; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; request.message.header.request.bodylen= htonl(key_length + request.message.header.request.extlen); diff --git a/libmemcachedutil/memcached_pool.c b/libmemcachedutil/memcached_pool.c index 7a4aa073..a1fc8c30 100644 --- a/libmemcachedutil/memcached_pool.c +++ b/libmemcachedutil/memcached_pool.c @@ -9,8 +9,8 @@ struct memcached_pool_st memcached_st *master; memcached_st **mmc; int firstfree; - int size; - int current_size; + uint32_t size; + uint32_t current_size; }; static memcached_return mutex_enter(pthread_mutex_t *mutex) diff --git a/tests/Makefile.am b/tests/Makefile.am index dd7ba749..70437c2e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,6 +21,7 @@ LIBS = noinst_HEADERS = test.h server.h ketama_test_cases.h noinst_PROGRAMS = testapp testplus udptest atomsmasher startservers +testapp_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION} testapp_SOURCES = test.c function.c server.c ../clients/generator.c ../clients/execute.c testapp_LDADD = $(LDADDS) diff --git a/tests/atomsmasher.c b/tests/atomsmasher.c index 500e2e8e..65a31dd4 100644 --- a/tests/atomsmasher.c +++ b/tests/atomsmasher.c @@ -73,8 +73,8 @@ infinite: uint32_t test_bit; uint8_t which; - test_bit= random() % GLOBAL_COUNT; - which= random() % 2; + test_bit= (uint32_t)(random() % GLOBAL_COUNT); + which= (uint8_t)(random() % 2); if (which == 0) { diff --git a/tests/function.c b/tests/function.c index 2262f1b2..fcf5b511 100644 --- a/tests/function.c +++ b/tests/function.c @@ -94,7 +94,7 @@ static test_return server_sort_test(memcached_st *ptr __attribute__((unused))) for (x= 0; x < TEST_PORT_COUNT; x++) { - test_ports[x]= random() % 64000; + test_ports[x]= (uint32_t)random() % 64000; rc= memcached_server_add_with_weight(local_memc, "localhost", test_ports[x], 0); assert(local_memc->number_of_hosts == x + 1); assert(local_memc->hosts[0].count == x+1); @@ -165,7 +165,7 @@ static test_return server_unsort_test(memcached_st *ptr __attribute__((unused)) for (x= 0; x < TEST_PORT_COUNT; x++) { - test_ports[x]= random() % 64000; + test_ports[x]= (uint32_t)(random() % 64000); rc= memcached_server_add_with_weight(local_memc, "localhost", test_ports[x], 0); assert(local_memc->number_of_hosts == x+1); assert(local_memc->hosts[0].count == x+1); @@ -1581,12 +1581,12 @@ static test_return user_supplied_bug1(memcached_st *memc) { unsigned int j= 0; - size= (rand() % ( 5 * 1024 ) ) + 400; + size= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400; memset(randomstuff, 0, 6 * 1024); assert(size < 6 * 1024); /* Being safe here */ for (j= 0 ; j < size ;j++) - randomstuff[j] = (char) (rand() % 26) + 97; + randomstuff[j] = (signed char) ((rand() % 26) + 97); total += size; sprintf(key, "%d", x); @@ -1798,7 +1798,7 @@ static test_return user_supplied_bug5(memcached_st *memc) char insert_data[VALUE_SIZE_BUG5]; for (x= 0; x < VALUE_SIZE_BUG5; x++) - insert_data[x]= rand(); + insert_data[x]= (signed char)rand(); memcached_flush(memc, 0); value= memcached_get(memc, keys[0], key_length[0], @@ -1856,7 +1856,7 @@ static test_return user_supplied_bug6(memcached_st *memc) char insert_data[VALUE_SIZE_BUG5]; for (x= 0; x < VALUE_SIZE_BUG5; x++) - insert_data[x]= rand(); + insert_data[x]= (signed char)rand(); memcached_flush(memc, 0); value= memcached_get(memc, keys[0], key_length[0], @@ -1951,7 +1951,7 @@ static test_return user_supplied_bug7(memcached_st *memc) char insert_data[VALUE_SIZE_BUG5]; for (x= 0; x < VALUE_SIZE_BUG5; x++) - insert_data[x]= rand(); + insert_data[x]= (signed char)rand(); memcached_flush(memc, 0); @@ -2032,7 +2032,7 @@ static test_return user_supplied_bug10(memcached_st *memc) char *value; size_t value_length= 512; unsigned int x; - int key_len= 3; + size_t key_len= 3; memcached_return rc; unsigned int set= 1; memcached_st *mclone= memcached_clone(NULL, memc); @@ -2041,7 +2041,8 @@ static test_return user_supplied_bug10(memcached_st *memc) memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, set); memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, set); timeout= 2; - memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout); + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, + (uint64_t)timeout); value = (char*)malloc(value_length * sizeof(char)); @@ -2074,7 +2075,7 @@ static test_return user_supplied_bug11(memcached_st *memc) char *value; size_t value_length= 512; unsigned int x; - int key_len= 3; + size_t key_len= 3; memcached_return rc; unsigned int set= 1; int32_t timeout; @@ -2083,7 +2084,8 @@ static test_return user_supplied_bug11(memcached_st *memc) memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, set); memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, set); timeout= -1; - memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout); + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, + (size_t)timeout); timeout= (int32_t)memcached_behavior_get(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT); @@ -2191,7 +2193,7 @@ static test_return user_supplied_bug13(memcached_st *memc) */ static test_return user_supplied_bug14(memcached_st *memc) { - int setter= 1; + size_t setter= 1; memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter); memcached_return rc; char *key= "foo"; @@ -2384,7 +2386,7 @@ static test_return user_supplied_bug20(memcached_st *memc) static test_return user_supplied_bug18(memcached_st *trash) { memcached_return rc; - int value; + uint64_t value; int x; memcached_server_st *server_pool; memcached_st *memc; @@ -2696,7 +2698,7 @@ static test_return generate_data_with_stats(memcached_st *memc) } static test_return generate_buffer_data(memcached_st *memc) { - int latch= 0; + size_t latch= 0; latch= 1; memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, latch); @@ -2848,7 +2850,7 @@ static test_return delete_generate(memcached_st *memc) static test_return delete_buffer_generate(memcached_st *memc) { - int latch= 0; + size_t latch= 0; unsigned int x; latch= 1; @@ -3289,13 +3291,13 @@ static memcached_return pre_settimer(memcached_st *memc) static memcached_return poll_timeout(memcached_st *memc) { - int32_t timeout; + size_t timeout; timeout= 100; memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout); - timeout= (int32_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT); + timeout= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT); assert(timeout == 100); @@ -3320,7 +3322,7 @@ static test_return noreply_test(memcached_st *memc) for (int x=0; x < 100; ++x) { char key[10]; - size_t len= sprintf(key, "%d", x); + size_t len= (size_t)sprintf(key, "%d", x); switch (count) { case 0: @@ -3352,7 +3354,7 @@ static test_return noreply_test(memcached_st *memc) */ int no_msg=0; for (uint32_t x=0; x < memc->number_of_hosts; ++x) - no_msg+=memc->hosts[x].cursor_active; + no_msg+=(int)(memc->hosts[x].cursor_active); assert(no_msg == 0); assert(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS); @@ -3363,7 +3365,7 @@ static test_return noreply_test(memcached_st *memc) for (int x=0; x < 100; ++x) { char key[10]; - size_t len= sprintf(key, "%d", x); + size_t len= (size_t)sprintf(key, "%d", x); size_t length; uint32_t flags; char* value=memcached_get(memc, key, strlen(key), diff --git a/tests/server.c b/tests/server.c index 8679c624..e06fbd57 100644 --- a/tests/server.c +++ b/tests/server.c @@ -50,7 +50,7 @@ void server_startup(server_startup_st *construct) { if (fgets(buffer, sizeof(buffer), fp) != NULL) { - pid_t pid = atol(buffer); + pid_t pid = (pid_t)atol(buffer); if (pid != 0) kill(pid, SIGTERM); } @@ -84,7 +84,7 @@ void server_startup(server_startup_st *construct) assert(construct->servers); - srandom(time(NULL)); + srandom((unsigned int)time(NULL)); for (x= 0; x < memcached_server_list_count(construct->servers); x++) { diff --git a/tests/test.c b/tests/test.c index a5371fee..78fe4a70 100644 --- a/tests/test.c +++ b/tests/test.c @@ -18,9 +18,9 @@ static long int timedif(struct timeval a, struct timeval b) { register int us, s; - us = a.tv_usec - b.tv_usec; + us = (int)(a.tv_usec - b.tv_usec); us /= 1000; - s = a.tv_sec - b.tv_sec; + s = (int)(a.tv_sec - b.tv_sec); s *= 1000; return s + us; }