summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDustin Sallings <dustin@spy.net>2009-04-02 11:42:19 -0700
committerDustin Sallings <dustin@spy.net>2009-04-02 12:24:55 -0700
commita4106cf31d24a4c200fbfc50660f24dcf903e08f (patch)
tree8d5f02513888154a0316d8a6cafd2ca9a7193a14
parent17df5c0e055e0de94feecab1eb89a79ab6836628 (diff)
downloadmemcached-a4106cf31d24a4c200fbfc50660f24dcf903e08f.tar.gz
Assert we're not overrunning a buffer in prefix stat creation.
-rw-r--r--stats.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/stats.c b/stats.c
index 87ae69a..636107e 100644
--- a/stats.c
+++ b/stats.c
@@ -162,7 +162,7 @@ char *stats_prefix_dump(int *length) {
PREFIX_STATS *pfs;
char *buf;
int i, pos;
- size_t size;
+ size_t size = 0, written = 0, total_written = 0;
/*
* Figure out how big the buffer needs to be. This is the sum of the
@@ -185,9 +185,12 @@ char *stats_prefix_dump(int *length) {
pos = 0;
for (i = 0; i < PREFIX_HASH_SIZE; i++) {
for (pfs = prefix_stats[i]; NULL != pfs; pfs = pfs->next) {
- pos += snprintf(buf + pos, size-pos, format,
+ written = snprintf(buf + pos, size-pos, format,
pfs->prefix, pfs->num_gets, pfs->num_hits,
pfs->num_sets, pfs->num_deletes);
+ pos += written;
+ total_written += written;
+ assert(total_written < size);
}
}