Merge pull request #2401 from mattsta/fix/quicklist/pop

Fix quicklist Pop()
This commit is contained in:
Salvatore Sanfilippo 2015-02-24 17:13:39 +01:00
commit 5ff00ac8c1

View File

@ -1372,7 +1372,7 @@ REDIS_STATIC void *_quicklistSaver(unsigned char *data, unsigned int sz) {
unsigned char *vstr; unsigned char *vstr;
if (data) { if (data) {
vstr = zmalloc(sz); vstr = zmalloc(sz);
memcpy(data, vstr, sz); memcpy(vstr, data, sz);
return vstr; return vstr;
} }
return NULL; return NULL;
@ -1757,7 +1757,8 @@ int quicklistTest(int argc, char *argv[]) {
TEST("pop 1 string from 1") { TEST("pop 1 string from 1") {
quicklist *ql = quicklistNew(-2, options[_i]); quicklist *ql = quicklistNew(-2, options[_i]);
quicklistPushHead(ql, genstr("hello", 331), 32); char *populate = genstr("hello", 331);
quicklistPushHead(ql, populate, 32);
unsigned char *data; unsigned char *data;
unsigned int sz; unsigned int sz;
long long lv; long long lv;
@ -1765,6 +1766,9 @@ int quicklistTest(int argc, char *argv[]) {
quicklistPop(ql, QUICKLIST_HEAD, &data, &sz, &lv); quicklistPop(ql, QUICKLIST_HEAD, &data, &sz, &lv);
assert(data != NULL); assert(data != NULL);
assert(sz == 32); assert(sz == 32);
if (strcmp(populate, (char *)data))
ERR("Pop'd value (%.*s) didn't equal original value (%s)", sz,
data, populate);
zfree(data); zfree(data);
ql_verify(ql, 0, 0, 0, 0); ql_verify(ql, 0, 0, 0, 0);
quicklistRelease(ql); quicklistRelease(ql);
@ -1797,6 +1801,9 @@ int quicklistTest(int argc, char *argv[]) {
assert(ret == 1); assert(ret == 1);
assert(data != NULL); assert(data != NULL);
assert(sz == 32); assert(sz == 32);
if (strcmp(genstr("hello", 499 - i), (char *)data))
ERR("Pop'd value (%.*s) didn't equal original value (%s)",
sz, data, genstr("hello", 499 - i));
zfree(data); zfree(data);
} }
ql_verify(ql, 0, 0, 0, 0); ql_verify(ql, 0, 0, 0, 0);
@ -1816,6 +1823,10 @@ int quicklistTest(int argc, char *argv[]) {
assert(ret == 1); assert(ret == 1);
assert(data != NULL); assert(data != NULL);
assert(sz == 32); assert(sz == 32);
if (strcmp(genstr("hello", 499 - i), (char *)data))
ERR("Pop'd value (%.*s) didn't equal original value "
"(%s)",
sz, data, genstr("hello", 499 - i));
zfree(data); zfree(data);
} else { } else {
assert(ret == 0); assert(ret == 0);