Skip to content

Commit

Permalink
stats_prefix_* should not assume that all keys are zero-terminated
Browse files Browse the repository at this point in the history
  • Loading branch information
Trond Norbye authored and dustin committed Jan 3, 2009
1 parent b2e7e90 commit 46654a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ static void process_bin_update(conn *c) {
}

if (settings.detail_enabled) {
stats_prefix_record_set(key);
stats_prefix_record_set(key, nkey);
}

it = item_alloc(key, nkey, req->message.body.flags,
Expand Down Expand Up @@ -1510,7 +1510,7 @@ static void process_bin_append_prepend(conn *c) {
}

if (settings.detail_enabled) {
stats_prefix_record_set(key);
stats_prefix_record_set(key, nkey);
}

it = item_alloc(key, nkey, 0, 0, vlen+2);
Expand Down Expand Up @@ -1583,7 +1583,7 @@ static void process_bin_delete(conn *c) {
}

if (settings.detail_enabled) {
stats_prefix_record_delete(key);
stats_prefix_record_delete(key, nkey);
}

it = item_get(key, nkey);
Expand Down Expand Up @@ -2160,7 +2160,7 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens,
stats_get_cmds++;
it = item_get(key, nkey);
if (settings.detail_enabled) {
stats_prefix_record_get(key, NULL != it);
stats_prefix_record_get(key, nkey, NULL != it);
}
if (it) {
if (i >= c->isize) {
Expand Down Expand Up @@ -2338,7 +2338,7 @@ static void process_update_command(conn *c, token_t *tokens, const size_t ntoken
}

if (settings.detail_enabled) {
stats_prefix_record_set(key);
stats_prefix_record_set(key, nkey);
}

if (settings.managed) {
Expand Down Expand Up @@ -2521,7 +2521,7 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken
}

if (settings.detail_enabled) {
stats_prefix_record_delete(key);
stats_prefix_record_delete(key, nkey);
}

it = item_get(key, nkey);
Expand Down
16 changes: 8 additions & 8 deletions stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ void stats_prefix_clear() {
* in the list.
*/
/*@null@*/
static PREFIX_STATS *stats_prefix_find(const char *key) {
static PREFIX_STATS *stats_prefix_find(const char *key, const size_t nkey) {
PREFIX_STATS *pfs;
uint32_t hashval;
size_t length;

assert(key != NULL);

for (length = 0; key[length] != '\0'; length++)
for (length = 0; key[length] != '\0' && length < nkey; length++)
if (key[length] == settings.prefix_delimiter)
break;

Expand Down Expand Up @@ -113,11 +113,11 @@ static PREFIX_STATS *stats_prefix_find(const char *key) {
/*
* Records a "get" of a key.
*/
void stats_prefix_record_get(const char *key, const bool is_hit) {
void stats_prefix_record_get(const char *key, const size_t nkey, const bool is_hit) {
PREFIX_STATS *pfs;

STATS_LOCK();
pfs = stats_prefix_find(key);
pfs = stats_prefix_find(key, nkey);
if (NULL != pfs) {
pfs->num_gets++;
if (is_hit) {
Expand All @@ -130,11 +130,11 @@ void stats_prefix_record_get(const char *key, const bool is_hit) {
/*
* Records a "delete" of a key.
*/
void stats_prefix_record_delete(const char *key) {
void stats_prefix_record_delete(const char *key, const size_t nkey) {
PREFIX_STATS *pfs;

STATS_LOCK();
pfs = stats_prefix_find(key);
pfs = stats_prefix_find(key, nkey);
if (NULL != pfs) {
pfs->num_deletes++;
}
Expand All @@ -144,11 +144,11 @@ void stats_prefix_record_delete(const char *key) {
/*
* Records a "set" of a key.
*/
void stats_prefix_record_set(const char *key) {
void stats_prefix_record_set(const char *key, const size_t nkey) {
PREFIX_STATS *pfs;

STATS_LOCK();
pfs = stats_prefix_find(key);
pfs = stats_prefix_find(key, nkey);
if (NULL != pfs) {
pfs->num_sets++;
}
Expand Down
6 changes: 3 additions & 3 deletions stats.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* stats */
void stats_prefix_init(void);
void stats_prefix_clear(void);
void stats_prefix_record_get(const char *key, const bool is_hit);
void stats_prefix_record_delete(const char *key);
void stats_prefix_record_set(const char *key);
void stats_prefix_record_get(const char *key, const size_t nkey, const bool is_hit);
void stats_prefix_record_delete(const char *key, const size_t nkey);
void stats_prefix_record_set(const char *key, const size_t nkey);
/*@null@*/
char *stats_prefix_dump(int *length);

0 comments on commit 46654a8

Please sign in to comment.