From: Brian Aker Date: Sun, 27 Nov 2011 05:59:20 +0000 (-0800) Subject: Fix one of the valgrind issues in mem_function.cc test. X-Git-Tag: 1.0.3~4^2~3^2~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=2740396a3a5535f65b917ba858eef8c5a5ae07b3;p=awesomized%2Flibmemcached Fix one of the valgrind issues in mem_function.cc test. --- diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index a625036f..321b5fc0 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -2241,31 +2241,30 @@ static test_return_t user_supplied_bug3(memcached_st *memc) std::vector key_lengths; key_lengths.resize(HALDENBRAND_KEY_COUNT); - char **keys= static_cast(calloc(key_lengths.size(), sizeof(char *))); - test_true(keys); + std::vector keys; + keys.resize(key_lengths.size()); for (uint32_t x= 0; x < key_lengths.size(); x++) { char key[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1]; int key_length= snprintf(key, sizeof(key), "%u", x); - test_true(key_length); + test_true(key_length > 0 and key_length < MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1); keys[x]= strdup(key); - test_true(keys[x]); key_lengths[x]= key_length; - test_compare(size_t(key_length), strlen(keys[x])); } test_compare(MEMCACHED_SUCCESS, - memcached_mget(memc, (const char **)keys, &key_lengths[0], key_lengths.size())); + memcached_mget(memc, &keys[0], &key_lengths[0], key_lengths.size())); unsigned int keys_returned; test_compare(TEST_SUCCESS, fetch_all_results(memc, keys_returned, MEMCACHED_SUCCESS)); test_compare(HALDENBRAND_KEY_COUNT, keys_returned); - for (uint32_t x= 0; x < HALDENBRAND_KEY_COUNT; x++) + for (std::vector::iterator iter= keys.begin(); + iter != keys.end(); + iter++) { - free(keys[x]); + free(*iter); } - free(keys); return TEST_SUCCESS; } @@ -2923,23 +2922,22 @@ static test_return_t _user_supplied_bug21(memcached_st* memc, size_t key_count) std::vector key_lengths; key_lengths.resize(key_count); - char **keys= static_cast(calloc(key_lengths.size(), sizeof(char *))); - test_true(keys); + std::vector keys; + keys.resize(key_lengths.size()); for (unsigned int x= 0; x < key_lengths.size(); x++) { - char buffer[30]; - - snprintf(buffer, 30, "%u", x); - keys[x]= strdup(buffer); - test_true(keys[x]); - key_lengths[x]= strlen(keys[x]); + char key[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1]; + int key_length= snprintf(key, sizeof(key), "%u", x); + test_true(key_length > 0 and key_length < MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1); + keys[x]= strdup(key); + key_lengths[x]= key_length; } oldalarm= signal(SIGALRM, fail); alarm(5); test_compare_got(MEMCACHED_SUCCESS, - memcached_mget(memc_clone, (const char **)keys, &key_lengths[0], key_count), memcached_last_error_message(memc_clone)); + memcached_mget(memc_clone, &keys[0], &key_lengths[0], key_count), memcached_last_error_message(memc_clone)); alarm(0); signal(SIGALRM, oldalarm); @@ -2961,11 +2959,12 @@ static test_return_t _user_supplied_bug21(memcached_st* memc, size_t key_count) test_false(return_key[0]); test_false(return_value); - for (unsigned int x= 0; x < key_count; x++) + for (std::vector::iterator iter= keys.begin(); + iter != keys.end(); + iter++) { - free(keys[x]); + free(*iter); } - free(keys); memcached_free(memc_clone); diff --git a/tests/parser.cc b/tests/parser.cc index 92ee9547..32b0d9d8 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -467,13 +467,17 @@ test_return_t random_statement_build_test(memcached_st*) bool has_distribution; bool has_buffer_requests; bool has_udp; + bool has_binary; + bool has_verify_key; used_options_st() : has_hash(false), has_namespace(false), has_distribution(false), has_buffer_requests(false), - has_udp(false) + has_udp(false), + has_binary(false), + has_verify_key(false) { } } used_options; @@ -546,6 +550,34 @@ test_return_t random_statement_build_test(memcached_st*) } } + if (random_string.compare(0, test_literal_compare_param("--BINARY-PROTOCOL")) == 0) + { + if (used_options.has_binary) + { + continue; + } + used_options.has_binary= true; + + if (used_options.has_verify_key) + { + continue; + } + } + + if (random_string.compare(0, test_literal_compare_param("--VERIFY-KEY")) == 0) + { + if (used_options.has_verify_key) + { + continue; + } + used_options.has_verify_key= true; + + if (used_options.has_binary) + { + continue; + } + } + if (random_string.compare(0, test_literal_compare_param("--DISTRIBUTION")) == 0) { if (used_options.has_distribution)