X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=clients%2Fgenerator.c;h=5bce0301ab6ae848f9315ea5b85c186210c8f30a;hb=5c6d7ae6344412f19fec578a328904c7c1700880;hp=793157ef52666e611b4a8fd3a4bb7732876679bd;hpb=8fce86636639afaeac4ca0e869e8bcd833324a62;p=awesomized%2Flibmemcached diff --git a/clients/generator.c b/clients/generator.c index 793157ef..5bce0301 100644 --- a/clients/generator.c +++ b/clients/generator.c @@ -1,5 +1,8 @@ +#include "libmemcached/common.h" + #include #include +#include #include #include "generator.h" @@ -10,18 +13,23 @@ static const char ALPHANUMERICS[]= #define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1) +static size_t get_alpha_num(void) +{ + return (size_t)random() % ALPHANUMERICS_SIZE; +} + static void get_random_string(char *buffer, size_t size) { char *buffer_ptr= buffer; while (--size) - *buffer_ptr++= ALPHANUMERICS[random() % ALPHANUMERICS_SIZE]; - *buffer_ptr++= ALPHANUMERICS[random() % ALPHANUMERICS_SIZE]; + *buffer_ptr++= ALPHANUMERICS[get_alpha_num()]; + *buffer_ptr++= ALPHANUMERICS[get_alpha_num()]; } void pairs_free(pairs_st *pairs) { - unsigned int x; + uint32_t x; if (!pairs) return; @@ -36,27 +44,25 @@ void pairs_free(pairs_st *pairs) free(pairs); } -pairs_st *pairs_generate(unsigned long long number_of, size_t value_length) +pairs_st *pairs_generate(uint64_t number_of, size_t value_length) { unsigned int x; pairs_st *pairs; - pairs= (pairs_st*)malloc(sizeof(pairs_st) * (number_of+1)); + pairs= (pairs_st*)calloc((size_t)number_of + 1, sizeof(pairs_st)); if (!pairs) goto error; - memset(pairs, 0, sizeof(pairs_st) * (number_of+1)); - for (x= 0; x < number_of; x++) { - pairs[x].key= (char *)malloc(sizeof(char) * 100); + pairs[x].key= (char *)calloc(100, sizeof(char)); if (!pairs[x].key) goto error; get_random_string(pairs[x].key, 100); pairs[x].key_length= 100; - pairs[x].value= (char *)malloc(sizeof(char) * value_length); + pairs[x].value= (char *)calloc(value_length, sizeof(char)); if (!pairs[x].value) goto error; get_random_string(pairs[x].value, value_length);