From: Brian Aker Date: Fri, 18 Dec 2009 18:46:19 +0000 (-0800) Subject: ICC and test fix. X-Git-Tag: 0.37~55 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=e0c60fb6c74608ed7b935ff27042e8df0cf1ae2d;p=m6w6%2Flibmemcached ICC and test fix. --- diff --git a/clients/memcapable.c b/clients/memcapable.c index c70afa33..36be2e55 100644 --- a/clients/memcapable.c +++ b/clients/memcapable.c @@ -218,7 +218,7 @@ static enum test_return ensure(bool val, const char *expression, const char *fil if (!val) { if (verbose) - fprintf(stderr, "\n%s:%u: %s", file, line, expression); + fprintf(stderr, "\n%s:%d: %s", file, line, expression); if (do_core) abort(); diff --git a/clients/memcp.c b/clients/memcp.c index 617057b3..8109ea7e 100644 --- a/clients/memcp.c +++ b/clients/memcp.c @@ -42,6 +42,33 @@ static int opt_method= OPT_SET; static uint32_t opt_flags= 0; static time_t opt_expires= 0; +static long strtol_wrapper(const char *nptr, int base, bool *error) +{ + long val; + char *endptr; + + errno= 0; /* To distinguish success/failure after call */ + val= strtol(nptr, &endptr, base); + + /* Check for various possible errors */ + + if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) + || (errno != 0 && val == 0)) + { + *error= true; + return 0; + } + + if (endptr == nptr) + { + *error= true; + return 0; + } + + *error= false; + return val; +} + int main(int argc, char *argv[]) { memcached_st *memc; @@ -220,11 +247,26 @@ static void options_parse(int argc, char *argv[]) opt_servers= strdup(optarg); break; case OPT_FLAG: /* --flag */ - opt_flags= (uint32_t)strtol(optarg, (char **)NULL, 16); - break; + { + bool strtol_error; + opt_flags= (uint32_t)strtol_wrapper(optarg, 16, &strtol_error); + if (strtol_error == true) + { + fprintf(stderr, "Bad value passed via --flag\n"); + exit(1); + } + break; + } case OPT_EXPIRE: /* --expire */ - opt_expires= (time_t)strtoll(optarg, (char **)NULL, 10); - break; + { + bool strtol_error; + opt_expires= (time_t)strtol_wrapper(optarg, 16, &strtol_error); + if (strtol_error == true) + { + fprintf(stderr, "Bad value passed via --flag\n"); + exit(1); + } + } case OPT_SET: opt_method= OPT_SET; break; diff --git a/clients/memslap.c b/clients/memslap.c index ac35e9d2..47be3c37 100644 --- a/clients/memslap.c +++ b/clients/memslap.c @@ -164,7 +164,7 @@ static void ms_global_struct_destroy() */ static void ms_version_command(const char *command_name) { - printf("%s v%u.%u\n", command_name, 1, 0); + printf("%s v%u.%u\n", command_name, 1U, 0U); exit(0); } @@ -287,7 +287,7 @@ void ms_help_command(const char *command_name, const char *description) { char *help_message= NULL; - printf("%s v%u.%u\n", command_name, 1, 0); + printf("%s v%u.%u\n", command_name, 1U, 0U); printf(" %s\n\n", description); printf( "Usage:\n" diff --git a/clients/memstat.c b/clients/memstat.c index c8769d52..42503d55 100644 --- a/clients/memstat.c +++ b/clients/memstat.c @@ -244,7 +244,7 @@ static void print_server_listing(memcached_st *memc, memcached_stat_st *memc_sta list= memcached_stat_get_keys(memc, &memc_stat[x], &rc); printf("Server: %s (%u)\n", memcached_server_name(memc, server_list[x]), - memcached_server_port(memc, server_list[x])); + (uint32_t)memcached_server_port(memc, server_list[x])); for (ptr= list; *ptr; ptr++) { char *value= memcached_stat_get_value(memc, &memc_stat[x], *ptr, &rc); @@ -266,7 +266,7 @@ static void print_analysis_report(memcached_st *memc, printf("Memcached Cluster Analysis Report\n\n"); - printf("\tNumber of Servers Analyzed : %d\n", server_count); + printf("\tNumber of Servers Analyzed : %u\n", server_count); printf("\tAverage Item Size (incl/overhead) : %u bytes\n", report->average_item_size); @@ -279,15 +279,15 @@ static void print_analysis_report(memcached_st *memc, printf("\n"); printf("\tNode with most memory consumption : %s:%u (%llu bytes)\n", memcached_server_name(memc, server_list[report->most_consumed_server]), - memcached_server_port(memc, server_list[report->most_consumed_server]), + (uint32_t)memcached_server_port(memc, server_list[report->most_consumed_server]), (unsigned long long)report->most_used_bytes); printf("\tNode with least free space : %s:%u (%llu bytes remaining)\n", memcached_server_name(memc, server_list[report->least_free_server]), - memcached_server_port(memc, server_list[report->least_free_server]), + (uint32_t)memcached_server_port(memc, server_list[report->least_free_server]), (unsigned long long)report->least_remaining_bytes); printf("\tNode with longest uptime : %s:%u (%us)\n", memcached_server_name(memc, server_list[report->oldest_server]), - memcached_server_port(memc, server_list[report->oldest_server]), + (uint32_t)memcached_server_port(memc, server_list[report->oldest_server]), report->longest_uptime); printf("\tPool-wide Hit Ratio : %1.f%%\n", report->pool_hit_ratio); printf("\n"); diff --git a/libhashkit/ketama.c b/libhashkit/ketama.c index 50309bbc..e56594cf 100644 --- a/libhashkit/ketama.c +++ b/libhashkit/ketama.c @@ -119,7 +119,7 @@ int update_continuum(hashkit_st *hashkit) if (hashkit->continuum_key_fn == NULL) { - sort_host_length= (size_t) snprintf(sort_host, HASHKIT_CONTINUUM_KEY_SIZE, "%d", + sort_host_length= (size_t) snprintf(sort_host, HASHKIT_CONTINUUM_KEY_SIZE, "%u", points_index); } else diff --git a/libmemcached/storage.c b/libmemcached/storage.c index d3e44e9c..f121364d 100644 --- a/libmemcached/storage.c +++ b/libmemcached/storage.c @@ -1,5 +1,5 @@ /* LibMemcached - * Copyright (C) 2006-2009 Brian Aker + * Copyright (C) 2006-2009 Brian Aker * All rights reserved. * * Use and distribution licensed under the BSD license. See @@ -45,21 +45,21 @@ static inline const char *storage_op_string(memcached_storage_action_t verb) } static memcached_return_t memcached_send_binary(memcached_st *ptr, - const char *master_key, + const char *master_key, size_t master_key_length, - const char *key, - size_t key_length, - const char *value, - size_t value_length, + const char *key, + size_t key_length, + const char *value, + size_t value_length, time_t expiration, uint32_t flags, uint64_t cas, memcached_storage_action_t verb); -static inline memcached_return_t memcached_send(memcached_st *ptr, - const char *master_key, size_t master_key_length, - const char *key, size_t key_length, - const char *value, size_t value_length, +static inline memcached_return_t memcached_send(memcached_st *ptr, + const char *master_key, size_t master_key_length, + const char *key, size_t key_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags, uint64_t cas, @@ -95,12 +95,12 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, if (cas) { - write_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "%s %s%.*s %u %llu %zu %llu%s\r\n", + write_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + "%s %s%.*s %u %llu %zu %llu%s\r\n", storage_op_string(verb), ptr->prefix_key, - (int)key_length, key, flags, - (unsigned long long)expiration, value_length, + (int)key_length, key, flags, + (unsigned long long)expiration, value_length, (unsigned long long)cas, (ptr->flags.no_reply) ? " noreply" : ""); } @@ -116,16 +116,16 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, buffer_ptr= memcpy((buffer_ptr + strlen(command)), ptr->prefix_key, strlen(ptr->prefix_key)); /* Copy in the key, adjust point if a key prefix was used. */ - buffer_ptr= memcpy(buffer_ptr + (ptr->prefix_key ? strlen(ptr->prefix_key) : 0), + buffer_ptr= memcpy(buffer_ptr + (ptr->prefix_key ? strlen(ptr->prefix_key) : 0), key, key_length); buffer_ptr+= key_length; - buffer_ptr[0]= ' '; + buffer_ptr[0]= ' '; buffer_ptr++; write_length= (size_t)(buffer_ptr - buffer); - write_length+= (size_t) snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE, - "%u %llu %zu%s\r\n", - flags, + write_length+= (size_t) snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE, + "%u %llu %zu%s\r\n", + flags, (unsigned long long)expiration, value_length, ptr->flags.no_reply ? " noreply" : ""); } @@ -182,7 +182,7 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, if (rc == MEMCACHED_STORED) return MEMCACHED_SUCCESS; - else + else return rc; error: @@ -192,177 +192,177 @@ error: } -memcached_return_t memcached_set(memcached_st *ptr, const char *key, size_t key_length, - const char *value, size_t value_length, +memcached_return_t memcached_set(memcached_st *ptr, const char *key, size_t key_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags) { memcached_return_t rc; LIBMEMCACHED_MEMCACHED_SET_START(); - rc= memcached_send(ptr, key, key_length, + rc= memcached_send(ptr, key, key_length, key, key_length, value, value_length, expiration, flags, 0, SET_OP); LIBMEMCACHED_MEMCACHED_SET_END(); return rc; } -memcached_return_t memcached_add(memcached_st *ptr, +memcached_return_t memcached_add(memcached_st *ptr, const char *key, size_t key_length, - const char *value, size_t value_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags) { memcached_return_t rc; LIBMEMCACHED_MEMCACHED_ADD_START(); - rc= memcached_send(ptr, key, key_length, + rc= memcached_send(ptr, key, key_length, key, key_length, value, value_length, expiration, flags, 0, ADD_OP); LIBMEMCACHED_MEMCACHED_ADD_END(); return rc; } -memcached_return_t memcached_replace(memcached_st *ptr, +memcached_return_t memcached_replace(memcached_st *ptr, const char *key, size_t key_length, - const char *value, size_t value_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags) { memcached_return_t rc; LIBMEMCACHED_MEMCACHED_REPLACE_START(); - rc= memcached_send(ptr, key, key_length, + rc= memcached_send(ptr, key, key_length, key, key_length, value, value_length, expiration, flags, 0, REPLACE_OP); LIBMEMCACHED_MEMCACHED_REPLACE_END(); return rc; } -memcached_return_t memcached_prepend(memcached_st *ptr, +memcached_return_t memcached_prepend(memcached_st *ptr, const char *key, size_t key_length, - const char *value, size_t value_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags) { memcached_return_t rc; - rc= memcached_send(ptr, key, key_length, + rc= memcached_send(ptr, key, key_length, key, key_length, value, value_length, expiration, flags, 0, PREPEND_OP); return rc; } -memcached_return_t memcached_append(memcached_st *ptr, +memcached_return_t memcached_append(memcached_st *ptr, const char *key, size_t key_length, - const char *value, size_t value_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags) { memcached_return_t rc; - rc= memcached_send(ptr, key, key_length, + rc= memcached_send(ptr, key, key_length, key, key_length, value, value_length, expiration, flags, 0, APPEND_OP); return rc; } -memcached_return_t memcached_cas(memcached_st *ptr, +memcached_return_t memcached_cas(memcached_st *ptr, const char *key, size_t key_length, - const char *value, size_t value_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags, uint64_t cas) { memcached_return_t rc; - rc= memcached_send(ptr, key, key_length, + rc= memcached_send(ptr, key, key_length, key, key_length, value, value_length, expiration, flags, cas, CAS_OP); return rc; } -memcached_return_t memcached_set_by_key(memcached_st *ptr, - const char *master_key __attribute__((unused)), - size_t master_key_length __attribute__((unused)), - const char *key, size_t key_length, - const char *value, size_t value_length, +memcached_return_t memcached_set_by_key(memcached_st *ptr, + const char *master_key __attribute__((unused)), + size_t master_key_length __attribute__((unused)), + const char *key, size_t key_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags) { memcached_return_t rc; LIBMEMCACHED_MEMCACHED_SET_START(); - rc= memcached_send(ptr, master_key, master_key_length, + rc= memcached_send(ptr, master_key, master_key_length, key, key_length, value, value_length, expiration, flags, 0, SET_OP); LIBMEMCACHED_MEMCACHED_SET_END(); return rc; } -memcached_return_t memcached_add_by_key(memcached_st *ptr, +memcached_return_t memcached_add_by_key(memcached_st *ptr, const char *master_key, size_t master_key_length, const char *key, size_t key_length, - const char *value, size_t value_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags) { memcached_return_t rc; LIBMEMCACHED_MEMCACHED_ADD_START(); - rc= memcached_send(ptr, master_key, master_key_length, + rc= memcached_send(ptr, master_key, master_key_length, key, key_length, value, value_length, expiration, flags, 0, ADD_OP); LIBMEMCACHED_MEMCACHED_ADD_END(); return rc; } -memcached_return_t memcached_replace_by_key(memcached_st *ptr, +memcached_return_t memcached_replace_by_key(memcached_st *ptr, const char *master_key, size_t master_key_length, const char *key, size_t key_length, - const char *value, size_t value_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags) { memcached_return_t rc; LIBMEMCACHED_MEMCACHED_REPLACE_START(); - rc= memcached_send(ptr, master_key, master_key_length, + rc= memcached_send(ptr, master_key, master_key_length, key, key_length, value, value_length, expiration, flags, 0, REPLACE_OP); LIBMEMCACHED_MEMCACHED_REPLACE_END(); return rc; } -memcached_return_t memcached_prepend_by_key(memcached_st *ptr, +memcached_return_t memcached_prepend_by_key(memcached_st *ptr, const char *master_key, size_t master_key_length, const char *key, size_t key_length, - const char *value, size_t value_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags) { memcached_return_t rc; - rc= memcached_send(ptr, master_key, master_key_length, + rc= memcached_send(ptr, master_key, master_key_length, key, key_length, value, value_length, expiration, flags, 0, PREPEND_OP); return rc; } -memcached_return_t memcached_append_by_key(memcached_st *ptr, +memcached_return_t memcached_append_by_key(memcached_st *ptr, const char *master_key, size_t master_key_length, const char *key, size_t key_length, - const char *value, size_t value_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags) { memcached_return_t rc; - rc= memcached_send(ptr, master_key, master_key_length, + rc= memcached_send(ptr, master_key, master_key_length, key, key_length, value, value_length, expiration, flags, 0, APPEND_OP); return rc; } -memcached_return_t memcached_cas_by_key(memcached_st *ptr, +memcached_return_t memcached_cas_by_key(memcached_st *ptr, const char *master_key, size_t master_key_length, const char *key, size_t key_length, - const char *value, size_t value_length, + const char *value, size_t value_length, time_t expiration, uint32_t flags, uint64_t cas) { memcached_return_t rc; - rc= memcached_send(ptr, master_key, master_key_length, + rc= memcached_send(ptr, master_key, master_key_length, key, key_length, value, value_length, expiration, flags, cas, CAS_OP); return rc; @@ -427,12 +427,12 @@ static inline uint8_t get_com_code(memcached_storage_action_t verb, bool noreply static memcached_return_t memcached_send_binary(memcached_st *ptr, - const char *master_key, + const char *master_key, size_t master_key_length, const char *key, - size_t key_length, - const char *value, - size_t value_length, + size_t key_length, + const char *value, + size_t value_length, time_t expiration, uint32_t flags, uint64_t cas, @@ -441,7 +441,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, uint8_t flush; protocol_binary_request_set request= {.bytes= {0}}; size_t send_length= sizeof(request.bytes); - uint32_t server_key= memcached_generate_hash(ptr, master_key, + uint32_t server_key= memcached_generate_hash(ptr, master_key, master_key_length); memcached_server_st *server= &ptr->hosts[server_key]; bool noreply= server->root->flags.no_reply; @@ -452,14 +452,14 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; if (verb == APPEND_OP || verb == PREPEND_OP) send_length -= 8; /* append & prepend does not contain extras! */ - else + else { request.message.header.request.extlen= 8; - request.message.body.flags= htonl(flags); + request.message.body.flags= htonl(flags); request.message.body.expiration= htonl((uint32_t)expiration); } - request.message.header.request.bodylen= htonl((uint32_t) (key_length + value_length + + request.message.header.request.bodylen= htonl((uint32_t) (key_length + value_length + request.message.header.request.extlen)); if (cas) @@ -480,13 +480,13 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, /* write the header */ if ((memcached_do(server, (const char*)request.bytes, send_length, 0) != MEMCACHED_SUCCESS) || (memcached_io_write(server, key, key_length, 0) == -1) || - (memcached_io_write(server, value, value_length, (char) flush) == -1)) + (memcached_io_write(server, value, value_length, (char) flush) == -1)) { memcached_io_reset(server); return MEMCACHED_WRITE_FAILURE; } - unlikely (verb == SET_OP && ptr->number_of_replicas > 0) + unlikely (verb == SET_OP && ptr->number_of_replicas > 0) { request.message.header.request.opcode= PROTOCOL_BINARY_CMD_SETQ; @@ -497,7 +497,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, server_key= 0; memcached_server_st *srv= &ptr->hosts[server_key]; - if ((memcached_do(srv, (const char*)request.bytes, + if ((memcached_do(srv, (const char*)request.bytes, send_length, 0) != MEMCACHED_SUCCESS) || (memcached_io_write(srv, key, key_length, 0) == -1) || (memcached_io_write(srv, value, value_length, (char) flush) == -1)) @@ -513,6 +513,6 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, if (noreply) return MEMCACHED_SUCCESS; - return memcached_response(server, NULL, 0, NULL); + return memcached_response(server, NULL, 0, NULL); } diff --git a/tests/function.c b/tests/function.c index a580f396..8160dadb 100644 --- a/tests/function.c +++ b/tests/function.c @@ -1845,6 +1845,7 @@ static test_return_t behavior_test(memcached_st *memc) value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS); memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, value + 1); test_truth((value + 1) == memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS)); + return TEST_SUCCESS; } @@ -5520,7 +5521,6 @@ test_st tests[] ={ {"clone_test", 0, (test_callback_fn)clone_test }, {"connection_test", 0, (test_callback_fn)connection_test}, {"callback_test", 0, (test_callback_fn)callback_test}, - {"behavior_test", 0, (test_callback_fn)behavior_test}, {"userdata_test", 0, (test_callback_fn)userdata_test}, {"error", 0, (test_callback_fn)error_test }, {"set", 0, (test_callback_fn)set_test }, @@ -5555,8 +5555,6 @@ test_st tests[] ={ {"add_host_test", 0, (test_callback_fn)add_host_test }, {"add_host_test_1", 0, (test_callback_fn)add_host_test1 }, {"get_stats_keys", 0, (test_callback_fn)get_stats_keys }, - {"behavior_test", 0, (test_callback_fn)get_stats_keys }, - {"callback_test", 0, (test_callback_fn)get_stats_keys }, {"version_string_test", 0, (test_callback_fn)version_string_test}, {"bad_key", 1, (test_callback_fn)bad_key_test }, {"memcached_server_cursor", 1, (test_callback_fn)memcached_server_cursor_test }, @@ -5571,6 +5569,11 @@ test_st tests[] ={ {0, 0, 0} }; +test_st behavior_tests[] ={ + {"behavior_test", 0, (test_callback_fn)behavior_test}, + {0, 0, 0} +}; + test_st async_tests[] ={ {"add", 1, (test_callback_fn)add_wrapper }, {0, 0, 0} @@ -5790,6 +5793,7 @@ collection_st collection[] ={ {"replication", (test_callback_fn)pre_replication, 0, replication_tests}, {"replication_noblock", (test_callback_fn)pre_replication_noblock, 0, replication_tests}, {"regression", 0, 0, regression_tests}, + {"behaviors", 0, 0, behavior_tests}, {0, 0, 0, 0} };