Bad setting (found by Marc Rossi)
[awesomized/libmemcached] / src / generator.c
index df04d348faf4e98fbe56a096211ed24e90b2549f..793157ef52666e611b4a8fd3a4bb7732876679bd 100644 (file)
@@ -23,6 +23,9 @@ void pairs_free(pairs_st *pairs)
 {
   unsigned int x;
 
+  if (!pairs)
+    return;
+
   /* We free until we hit the null pair we stores during creation */
   for (x= 0; pairs[x].key; x++)
   {
@@ -33,7 +36,7 @@ void pairs_free(pairs_st *pairs)
   free(pairs);
 }
 
-pairs_st *pairs_generate(unsigned long long number_of)
+pairs_st *pairs_generate(unsigned long long number_of, size_t value_length)
 {
   unsigned int x;
   pairs_st *pairs;
@@ -53,11 +56,11 @@ pairs_st *pairs_generate(unsigned long long number_of)
     get_random_string(pairs[x].key, 100);
     pairs[x].key_length= 100;
 
-    pairs[x].value= (char *)malloc(sizeof(char) * 400);
+    pairs[x].value= (char *)malloc(sizeof(char) * value_length);
     if (!pairs[x].value)
       goto error;
-    get_random_string(pairs[x].value, 400);
-    pairs[x].value_length= 400;
+    get_random_string(pairs[x].value, value_length);
+    pairs[x].value_length= value_length;
   }
 
   return pairs;