Permalink
Browse files

MB-100 Fix incorrect sizeof() use in tests

Change-Id: I2aef80d12ffb043c75959aeaec12fb0b66ac5e31
Reviewed-on: http://review.couchbase.org/20714
Reviewed-by: Jens Alfke <jens@couchbase.com>
Tested-by: Jens Alfke <jens@couchbase.com>
  • Loading branch information...
1 parent c3caefa commit c79f436c07ed11431bca53ea919f26226c2fa2a1 @apage43 committed with Peter Wansch Sep 11, 2012
Showing with 7 additions and 3 deletions.
  1. +7 −3 tests/testapp.c
View
@@ -12,6 +12,8 @@
#include "macros.h"
#define ZERO(V) memset(&(V), 0, sizeof(V))
+//Only use the macro SETDOC with constants!
+//it uses sizeof()
#define SETDOC(N, I, D, M) \
setdoc(&testdocset.docs[N], &testdocset.infos[N], I, strlen(I), \
D, sizeof(D) - 1, M, strlen(M)); testdocset.datasize += sizeof(D) - 1;
@@ -192,11 +194,13 @@ static void test_save_docs(int count, const char *doc_tpl)
for (i = 0; i < count; ++i) {
idBuf = (char *) malloc(sizeof(char) * 32);
assert(idBuf != NULL);
- sprintf(idBuf, "doc%lu", (unsigned long)rand());
+ int idsize = sprintf(idBuf, "doc%lu", (unsigned long)rand());
valueBuf = (char *) malloc(sizeof(char) * (strlen(doc_tpl) + 20));
assert(valueBuf != NULL);
- sprintf(valueBuf, doc_tpl, i + 1);
- SETDOC(i, idBuf, valueBuf, zerometa);
+ int valsize = sprintf(valueBuf, doc_tpl, i + 1);
+ setdoc(&testdocset.docs[i], &testdocset.infos[i],
+ idBuf, idsize, valueBuf, valsize, zerometa, sizeof(zerometa));
+ testdocset.datasize += valsize;
}
docptrs = (Doc **) malloc(sizeof(Doc*) * count);

0 comments on commit c79f436

Please sign in to comment.