projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
m4: skip -fsanitize=object-size on clang
[awesomized/libmemcached]
/
clients
/
generator.cc
diff --git
a/clients/generator.cc
b/clients/generator.cc
index 80b398b251df3a73b0f476f0439a91553f8951b1..1f40daedbc6fd21a1b70fac8c6433d1c892d5ded 100644
(file)
--- a/
clients/generator.cc
+++ b/
clients/generator.cc
@@
-1,4
+1,5
@@
/* LibMemcached
/* LibMemcached
+ * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
* Copyright (C) 2006-2009 Brian Aker
* All rights reserved.
*
* Copyright (C) 2006-2009 Brian Aker
* All rights reserved.
*
@@
-9,14
+10,19
@@
*
*/
*
*/
-#include
"config.h"
+#include
<mem_config.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <stdint.h>
#include <stdint.h>
-#include <string.h>
-#include "generator.h"
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+#include <unistd.h>
+
+#include "clients/generator.h"
+
+#define KEY_BYTES 20
/* Use this for string generation */
static const char ALPHANUMERICS[]=
/* Use this for string generation */
static const char ALPHANUMERICS[]=
@@
-29,28
+35,32
@@
static size_t get_alpha_num(void)
return (size_t)random() % ALPHANUMERICS_SIZE;
}
return (size_t)random() % ALPHANUMERICS_SIZE;
}
-
static
void get_random_string(char *buffer, size_t size)
+void get_random_string(char *buffer, size_t size)
{
char *buffer_ptr= buffer;
while (--size)
{
char *buffer_ptr= buffer;
while (--size)
+ {
*buffer_ptr++= ALPHANUMERICS[get_alpha_num()];
*buffer_ptr++= ALPHANUMERICS[get_alpha_num()];
+ }
*buffer_ptr++= ALPHANUMERICS[get_alpha_num()];
}
void pairs_free(pairs_st *pairs)
{
*buffer_ptr++= ALPHANUMERICS[get_alpha_num()];
}
void pairs_free(pairs_st *pairs)
{
- uint32_t x;
-
- if (! pairs)
+ if (pairs == NULL)
+ {
return;
return;
+ }
/* We free until we hit the null pair we stores during creation */
/* We free until we hit the null pair we stores during creation */
- for (x= 0; pairs[x].key; x++)
+ for (
uint32_t
x= 0; pairs[x].key; x++)
{
free(pairs[x].key);
if (pairs[x].value)
{
free(pairs[x].key);
if (pairs[x].value)
+ {
free(pairs[x].value);
free(pairs[x].value);
+ }
}
free(pairs);
}
free(pairs);
@@
-58,27
+68,30
@@
void pairs_free(pairs_st *pairs)
pairs_st *pairs_generate(uint64_t 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*)calloc((size_t)number_of + 1, sizeof(pairs_st));
+ pairs_st *pairs= (pairs_st*)calloc((size_t)number_of + 1, sizeof(pairs_st));
- if (!pairs)
+ if (pairs == NULL)
+ {
goto error;
goto error;
+ }
- for (x= 0; x < number_of; x++)
+ for (
uint64_t
x= 0; x < number_of; x++)
{
{
- pairs[x].key= (char *)calloc(100, sizeof(char));
- if (!pairs[x].key)
+ pairs[x].key= (char *)calloc(KEY_BYTES, sizeof(char));
+
+ if (pairs[x].key == NULL)
goto error;
goto error;
- get_random_string(pairs[x].key, 100);
- pairs[x].key_length= 100;
+
+ get_random_string(pairs[x].key, KEY_BYTES);
+ pairs[x].key_length= KEY_BYTES;
if (value_length)
{
pairs[x].value= (char *)calloc(value_length, sizeof(char));
if (value_length)
{
pairs[x].value= (char *)calloc(value_length, sizeof(char));
- if (!pairs[x].value)
+
+ if (pairs[x].value == NULL)
goto error;
goto error;
+
get_random_string(pairs[x].value, value_length);
pairs[x].value_length= value_length;
}
get_random_string(pairs[x].value, value_length);
pairs[x].value_length= value_length;
}
@@
-91,6
+104,6
@@
pairs_st *pairs_generate(uint64_t number_of, size_t value_length)
return pairs;
error:
return pairs;
error:
-
fprintf(stderr, "Memory Allocation failure in pairs_generate.\n")
;
-
exit(0
);
+
std::cerr << "Memory Allocation failure in pairs_generate." << std::endl
;
+
exit(EXIT_SUCCESS
);
}
}