Skip to content

Commit 3638b03

Browse files
authored
Add some sanity checks on allocating functions (#50)
Try to have the same checks on both `binary_fuse8_allocate()` and on `binary_fuse16_allocate`: `size` parameter should be 2, at least
1 parent 3220808 commit 3638b03

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

include/binaryfusefilter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static inline bool binary_fuse8_allocate(uint32_t size,
211211
filter->SegmentLength = 262144;
212212
}
213213
filter->SegmentLengthMask = filter->SegmentLength - 1;
214-
double sizeFactor = binary_fuse_calculate_size_factor(arity, size);
214+
double sizeFactor = size <= 1 ? 0 : binary_fuse_calculate_size_factor(arity, size);
215215
uint32_t capacity = size <= 1 ? 0 : (uint32_t)(round((double)size * sizeFactor));
216216
uint32_t initSegmentCount =
217217
(capacity + filter->SegmentLength - 1) / filter->SegmentLength -
@@ -499,7 +499,7 @@ static inline bool binary_fuse16_allocate(uint32_t size,
499499
}
500500
filter->SegmentLengthMask = filter->SegmentLength - 1;
501501
double sizeFactor = size <= 1 ? 0 : binary_fuse_calculate_size_factor(arity, size);
502-
uint32_t capacity = (uint32_t)(round((double)size * sizeFactor));
502+
uint32_t capacity = size <= 1 ? 0 : (uint32_t)(round((double)size * sizeFactor));
503503
uint32_t initSegmentCount =
504504
(capacity + filter->SegmentLength - 1) / filter->SegmentLength -
505505
(arity - 1);

0 commit comments

Comments
 (0)