From: Date: Wed, 5 Mar 2008 20:30:00 +0000 (-0500) Subject: Fix for zero length values. X-Git-Tag: 0.20~1^2~70 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d25116faa1082bce63d0699d6f2442fcd569cfa4;p=awesomized%2Flibmemcached Fix for zero length values. --- diff --git a/ChangeLog b/ChangeLog index 46c15ea9..1d199b27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 0.17 * MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT added for connect timeout in non-block mode. + * Fix plus tests for non-zero value objects and flags. 0.16 Mon Feb 18 00:30:25 PST 2008 * Work on the UDP protocol diff --git a/lib/memcached_fetch.c b/lib/memcached_fetch.c index 96363684..37cec5d3 100644 --- a/lib/memcached_fetch.c +++ b/lib/memcached_fetch.c @@ -159,6 +159,8 @@ char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length, if (result_buffer->flags) *flags= result_buffer->flags; + else + *flags= 0; return memcached_string_c_copy(&result_buffer->value); } diff --git a/lib/memcached_io.c b/lib/memcached_io.c index 3b5b25af..b9261f3d 100644 --- a/lib/memcached_io.c +++ b/lib/memcached_io.c @@ -119,7 +119,6 @@ ssize_t memcached_io_read(memcached_server_st *ptr, } else { - WATCHPOINT_ASSERT(0); found_eof= 1; break; } diff --git a/lib/memcached_string.c b/lib/memcached_string.c index ad396118..1595ec61 100644 --- a/lib/memcached_string.c +++ b/lib/memcached_string.c @@ -140,6 +140,9 @@ char *memcached_string_c_copy(memcached_string_st *string) WATCHPOINT_ASSERT(string->is_allocated != MEMCACHED_USED); + if (memcached_string_length(string) == 0) + return NULL; + if (string->root->call_malloc) c_ptr= (char *)string->root->call_malloc(string->root, (memcached_string_length(string)+1) * sizeof(char)); else diff --git a/tests/function.c b/tests/function.c index 6bbaa40c..dd3af2ac 100644 --- a/tests/function.c +++ b/tests/function.c @@ -1837,6 +1837,46 @@ uint8_t user_supplied_bug14(memcached_st *memc) return 0; } +/* + Look for zero length value problems + */ +uint8_t user_supplied_bug15(memcached_st *memc) +{ + uint32_t x; + memcached_return rc; + char *key= "mykey"; + char *value; + size_t length; + uint32_t flags; + + for (x= 0; x < 2; x++) + { + rc= memcached_set(memc, key, strlen(key), + NULL, 0, + (time_t)0, (uint32_t)0); + + assert(rc == MEMCACHED_SUCCESS); + + value= memcached_get(memc, key, strlen(key), + &length, &flags, &rc); + + assert(rc == MEMCACHED_SUCCESS); + assert(value == NULL); + assert(length == 0); + assert(flags == 0); + + value= memcached_get(memc, key, strlen(key), + &length, &flags, &rc); + + assert(rc == MEMCACHED_SUCCESS); + assert(value == NULL); + assert(length == 0); + assert(flags == 0); + } + + return 0; +} + uint8_t result_static(memcached_st *memc) { memcached_result_st result; @@ -2480,6 +2520,7 @@ test_st user_tests[] ={ {"user_supplied_bug12", 1, user_supplied_bug12 }, {"user_supplied_bug13", 1, user_supplied_bug13 }, {"user_supplied_bug14", 1, user_supplied_bug14 }, + {"user_supplied_bug15", 1, user_supplied_bug15 }, {0, 0, 0} };