Merge pull request #3575 from deep011/unstable

fix a bug for quicklistDup() function
This commit is contained in:
Salvatore Sanfilippo 2016-11-02 11:00:24 +01:00 committed by GitHub
commit b3e707339d

View File

@ -1192,12 +1192,12 @@ quicklist *quicklistDup(quicklist *orig) {
current = current->next) { current = current->next) {
quicklistNode *node = quicklistCreateNode(); quicklistNode *node = quicklistCreateNode();
if (node->encoding == QUICKLIST_NODE_ENCODING_LZF) { if (current->encoding == QUICKLIST_NODE_ENCODING_LZF) {
quicklistLZF *lzf = (quicklistLZF *)node->zl; quicklistLZF *lzf = (quicklistLZF *)current->zl;
size_t lzf_sz = sizeof(*lzf) + lzf->sz; size_t lzf_sz = sizeof(*lzf) + lzf->sz;
node->zl = zmalloc(lzf_sz); node->zl = zmalloc(lzf_sz);
memcpy(node->zl, current->zl, lzf_sz); memcpy(node->zl, current->zl, lzf_sz);
} else if (node->encoding == QUICKLIST_NODE_ENCODING_RAW) { } else if (current->encoding == QUICKLIST_NODE_ENCODING_RAW) {
node->zl = zmalloc(current->sz); node->zl = zmalloc(current->sz);
memcpy(node->zl, current->zl, current->sz); memcpy(node->zl, current->zl, current->sz);
} }