summaryrefslogtreecommitdiff
path: root/src/ziplist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ziplist.c')
-rw-r--r--src/ziplist.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/ziplist.c b/src/ziplist.c
index 64a22adfc..34053d06a 100644
--- a/src/ziplist.c
+++ b/src/ziplist.c
@@ -613,7 +613,12 @@ static unsigned char *__ziplistInsert(unsigned char *zl, unsigned char *p, unsig
/* When the insert position is not equal to the tail, we need to
* make sure that the next entry can hold this entry's length in
* its prevlen field. */
+ int forcelarge = 0;
nextdiff = (p[0] != ZIP_END) ? zipPrevLenByteDiff(p,reqlen) : 0;
+ if (nextdiff == -4 && reqlen < 4) {
+ nextdiff = 0;
+ forcelarge = 1;
+ }
/* Store offset because a realloc may change the address of zl. */
offset = p-zl;
@@ -626,7 +631,10 @@ static unsigned char *__ziplistInsert(unsigned char *zl, unsigned char *p, unsig
memmove(p+reqlen,p-nextdiff,curlen-offset-1+nextdiff);
/* Encode this entry's raw length in the next entry. */
- zipPrevEncodeLength(p+reqlen,reqlen);
+ if (forcelarge)
+ zipPrevEncodeLengthForceLarge(p+reqlen,reqlen);
+ else
+ zipPrevEncodeLength(p+reqlen,reqlen);
/* Update offset for tail */
ZIPLIST_TAIL_OFFSET(zl) =