From: Date: Mon, 30 Jun 2008 16:01:46 +0000 (-0700) Subject: Clarified return type for prefix key in cases where it is too long. X-Git-Tag: 0.22~7 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=f47a36c604ce6bb5065944a71645750c228ccf88;p=m6w6%2Flibmemcached Clarified return type for prefix key in cases where it is too long. --- diff --git a/ChangeLog b/ChangeLog index 50d08772..d5c8734f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ + * Fixed bugs in stats output (thread output was wrong) + * Clarified MEMCACHED_BAD_KEY_PROVIDED is return for bad prefix key. + 0.22 * Found a bug in Flags return (Jacek Ostrowski) * Fixed issue with compiling on Visual Studio diff --git a/docs/memcached_callback.pod b/docs/memcached_callback.pod index e1b2fb16..1858302c 100755 --- a/docs/memcached_callback.pod +++ b/docs/memcached_callback.pod @@ -51,9 +51,10 @@ point of its execution all connections have been closed. You can set a value which will be used to create a domain for your keys. The value specified here will be prefixed to each of your keys. The value can not -be greater then MEMCACHED_PREFIX_KEY_MAX_SIZE and will reduce MEMCACHED_MAX_KEY by +be greater then MEMCACHED_PREFIX_KEY_MAX_SIZE - 1 and will reduce MEMCACHED_MAX_KEY by the value of your key. The prefix key is only applied to the primary key, -not the master key. +not the master key. MEMCACHED_FAILURE will be returned if no key is set. In the case +of a key which is too long MEMCACHED_BAD_KEY_PROVIDED will be returned. =item MEMCACHED_CALLBACK_USER_DATA diff --git a/libmemcached/memcached_callback.c b/libmemcached/memcached_callback.c index c231716d..ad1ce2b1 100644 --- a/libmemcached/memcached_callback.c +++ b/libmemcached/memcached_callback.c @@ -101,8 +101,16 @@ void *memcached_callback_get(memcached_st *ptr, { case MEMCACHED_CALLBACK_PREFIX_KEY: { - *error= ptr->prefix_key[0] != 0 ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE; - return (void *)ptr->prefix_key; + if (ptr->prefix_key[0] == 0) + { + *error= MEMCACHED_FAILURE; + return NULL; + } + else + { + *error= MEMCACHED_SUCCESS; + return (void *)ptr->prefix_key; + } } case MEMCACHED_CALLBACK_USER_DATA: { diff --git a/tests/function.c b/tests/function.c index 015fa49c..fb2f4bca 100644 --- a/tests/function.c +++ b/tests/function.c @@ -2006,7 +2006,6 @@ test_return user_supplied_bug15(memcached_st *memc) /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */ test_return user_supplied_bug16(memcached_st *memc) { - uint32_t x; memcached_return rc; char *key= "mykey"; char *value; @@ -2523,6 +2522,20 @@ memcached_return set_prefix(memcached_st *memc) assert(rc == MEMCACHED_SUCCESS); assert(memcmp(value, key, 4) == 0); + /* Set to Zero, and then Set to something too large */ + { + char *long_key= "This is more then the allotted number of characters"; + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL); + assert(rc == MEMCACHED_SUCCESS); + + value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc); + assert(rc == MEMCACHED_FAILURE); + assert(value == NULL); + + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, long_key); + assert(rc == MEMCACHED_BAD_KEY_PROVIDED); + } + return MEMCACHED_SUCCESS; }