28
28
*/
29
29
30
30
#include <errno.h>
31
+ #include <stdio.h>
31
32
#include <string.h>
32
33
33
34
#include "endianconv.h"
@@ -277,6 +278,13 @@ void streamGetEdgeID(stream *s, int first, int skip_tombstones, streamID *edge_i
277
278
streamIteratorStop (& si );
278
279
}
279
280
281
+ void checkListPackNotEmpty (unsigned char * lp ) {
282
+ if (lpBytes (lp ) == 0 ) {
283
+ fprintf (stderr , "Error: corrupted listpack found." );
284
+ abort ();
285
+ }
286
+ }
287
+
280
288
/* Trim the stream 's' according to args->trim_strategy, and return the
281
289
* number of elements removed from the stream. The 'approx' option, if non-zero,
282
290
* specifies that the trimming must be performed in a approximated way in
@@ -345,7 +353,7 @@ int64_t streamTrim(stream *s, streamAddTrimArgs *args) {
345
353
346
354
if (remove_node ) {
347
355
lpFree (lp );
348
- raxRemove (s -> rax_tree ,ri .key ,ri .key_len ,NULL );
356
+ checkedRaxRemove (s -> rax_tree , ri .key , ri .key_len , NULL );
349
357
raxSeek (& ri ,">=" ,ri .key ,ri .key_len );
350
358
s -> length -= entries ;
351
359
deleted += entries ;
@@ -444,6 +452,7 @@ int64_t streamTrim(stream *s, streamAddTrimArgs *args) {
444
452
445
453
/* Update the listpack with the new pointer. */
446
454
raxInsert (s -> rax_tree ,ri .key ,ri .key_len ,lp ,NULL );
455
+ checkListPackNotEmpty (lp );
447
456
448
457
break ; /* If we are here, there was enough to delete in the current
449
458
node, so no need to go to the next node. */
@@ -739,7 +748,7 @@ void streamIteratorRemoveEntry(streamIterator *si, streamID *current) {
739
748
/* If this is the last element in the listpack, we can remove the whole
740
749
* node. */
741
750
lpFree (lp );
742
- raxRemove (si -> stream -> rax_tree ,si -> ri .key ,si -> ri .key_len ,NULL );
751
+ checkedRaxRemove (si -> stream -> rax_tree , si -> ri .key , si -> ri .key_len , NULL );
743
752
} else {
744
753
/* In the base case we alter the counters of valid/deleted entries. */
745
754
lp = lpReplaceInteger (lp ,& p ,aux - 1 );
@@ -750,6 +759,8 @@ void streamIteratorRemoveEntry(streamIterator *si, streamID *current) {
750
759
/* Update the listpack with the new pointer. */
751
760
if (si -> lp != lp )
752
761
raxInsert (si -> stream -> rax_tree ,si -> ri .key ,si -> ri .key_len ,lp ,NULL );
762
+
763
+ checkListPackNotEmpty (lp );
753
764
}
754
765
755
766
/* Update the number of entries counter. */
0 commit comments