From: Brian Aker Date: Wed, 28 Nov 2007 16:30:38 +0000 (-0800) Subject: Longer test case added for server parsing. X-Git-Tag: 0.13~66 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=5c17e733976d4ce6287a68205a30d87f58f71ce1;p=awesomized%2Flibmemcached Longer test case added for server parsing. Test also looks at servers which can not be connected to. Removed special memset in md5. --- diff --git a/lib/md5.c b/lib/md5.c index 781aba83..61f8d692 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -30,6 +30,7 @@ documentation and/or software. */ +#include #include /* POINTER defines a generic pointer type */ @@ -80,8 +81,6 @@ static void Encode (unsigned char *output, UINT4 *input, unsigned int len); static void Decode(UINT4 *output, unsigned char *input, unsigned int len); -static void MD5_memcpy(unsigned char *, unsigned char *, unsigned int); -static void MD5_memset(unsigned char *, int, unsigned int); static unsigned char PADDING[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -178,7 +177,7 @@ static void MD5Update ( /* Transform as many times as possible. */ if (inputLen >= partLen) { - MD5_memcpy((POINTER)&context->buffer[idx], (POINTER)input, partLen); + memcpy((POINTER)&context->buffer[idx], (POINTER)input, partLen); MD5Transform(context->state, context->buffer); for (i = partLen; i + 63 < inputLen; i += 64) @@ -190,7 +189,7 @@ static void MD5Update ( i = 0; /* Buffer remaining input */ - MD5_memcpy((POINTER)&context->buffer[idx], (POINTER)&input[i], + memcpy((POINTER)&context->buffer[idx], (POINTER)&input[i], inputLen-i); } @@ -222,7 +221,7 @@ static void MD5Final ( /* Zeroize sensitive information. */ - MD5_memset ((POINTER)context, 0, sizeof (*context)); + memset((POINTER)context, 0, sizeof (*context)); } /* MD5 basic transformation. Transforms state based on block. @@ -315,7 +314,7 @@ static void MD5Transform ( /* Zeroize sensitive information. */ - MD5_memset ((POINTER)x, 0, sizeof (x)); + memset((POINTER)x, 0, sizeof (x)); } /* Encodes input (UINT4) into output (unsigned char). Assumes len is @@ -351,35 +350,3 @@ unsigned int len) output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); } - -/* Note: Replace "for loop" with standard memcpy if possible. - */ - -#ifndef MD5_memcpy -static void MD5_memcpy (output, input, len) -POINTER output; -POINTER input; -unsigned int len; -{ - unsigned int i; - - for (i = 0; i < len; i++) - output[i] = input[i]; -} -#endif - -/* Note: Replace "for loop" with standard memset if possible. - */ - -#ifndef MD5_memset -static void MD5_memset (output, value, len) -POINTER output; -int value; -unsigned int len; -{ - unsigned int i; - - for (i = 0; i < len; i++) - ((char *)output)[i] = (char)value; -} -#endif diff --git a/lib/memcached_hosts.c b/lib/memcached_hosts.c index 4b871d6b..0090625c 100644 --- a/lib/memcached_hosts.c +++ b/lib/memcached_hosts.c @@ -41,7 +41,7 @@ memcached_return memcached_server_push(memcached_st *ptr, memcached_server_st *l for (x= 0; x < count; x++) { - WATCHPOINT_ASSERT(list[x].hostname[0] == 0); + WATCHPOINT_ASSERT(list[x].hostname[0] != 0); host_reset(&ptr->hosts[ptr->number_of_hosts], list[x].hostname, list[x].port, list[x].type); ptr->number_of_hosts++; @@ -146,7 +146,6 @@ memcached_server_st *memcached_server_list_append(memcached_server_st *ptr, unsigned int memcached_server_list_count(memcached_server_st *ptr) { - if (ptr == NULL) return 0; @@ -155,8 +154,6 @@ unsigned int memcached_server_list_count(memcached_server_st *ptr) void memcached_server_list_free(memcached_server_st *ptr) { - unsigned int x; - if (ptr == NULL) return; diff --git a/tests/function.c b/tests/function.c index b5af2b50..c42cc82b 100644 --- a/tests/function.c +++ b/tests/function.c @@ -1253,6 +1253,36 @@ uint8_t user_supplied_bug6(memcached_st *memc) return 0; } +uint8_t user_supplied_bug8(memcached_st *memc) +{ + memcached_return rc; + memcached_st *mine; + memcached_st *clone; + + memcached_server_st *servers; + char *server_list= "memcache1.memcache.bk.sapo.pt:11211, memcache1.memcache.bk.sapo.pt:11212, memcache1.memcache.bk.sapo.pt:11213, memcache1.memcache.bk.sapo.pt:11214, memcache2.memcache.bk.sapo.pt:11211, memcache2.memcache.bk.sapo.pt:11212, memcache2.memcache.bk.sapo.pt:11213, memcache2.memcache.bk.sapo.pt:11214"; + + servers= memcached_servers_parse(server_list); + assert(servers); + + mine= memcached_create(NULL); + rc= memcached_server_push(mine, servers); + assert(rc == MEMCACHED_SUCCESS); + memcached_server_list_free(servers); + + assert(mine); + clone= memcached_clone(NULL, mine); + + memcached_quit(mine); + memcached_quit(clone); + + + memcached_free(mine); + memcached_free(clone); + + return 0; +} + /* Test flag store/retrieve */ uint8_t user_supplied_bug7(memcached_st *memc) { @@ -1775,6 +1805,7 @@ test_st user_tests[] ={ {"user_supplied_bug5", 1, user_supplied_bug5 }, {"user_supplied_bug6", 1, user_supplied_bug6 }, {"user_supplied_bug7", 1, user_supplied_bug7 }, + {"user_supplied_bug8", 1, user_supplied_bug8 }, {0, 0, 0} };