Skip to content

Commit

Permalink
Bugfix: partial match using fromJust in IndexCompact.search
Browse files Browse the repository at this point in the history
We were using `fromJust` on the result of `bitIndexFromToRev`, even though it is
not guaranteed to return a `Just`. See #204 for more info.
  • Loading branch information
jorisdral committed May 6, 2024
1 parent 2375684 commit 181e2b8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Database/LSMTree/Internal/IndexCompact.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import Data.ByteString.Short (ShortByteString (..))
import Data.Map.Range (Bound (..))
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromJust)
import Data.Maybe (fromMaybe)
import Data.Primitive.ByteArray (ByteArray (..), indexByteArray,
sizeofByteArray)
import Data.Primitive.Types (sizeOf)
Expand Down Expand Up @@ -566,7 +566,7 @@ search k IndexCompact{..} = -- Pre: @[0, V.length icPrimary)@
Just !i -> -- Post: @[lb, i]@.
if unBit $ icClashes VU.! i then
-- Post: @[lb, i]@, now in clash recovery mode.
let !i1 = PageNo $ fromJust $
let !i1 = PageNo $ fromMaybe lb $
bitIndexFromToRev (BoundInclusive lb) (BoundInclusive i) (Bit False) icClashes
!i2 = maybe (PageNo 0) snd $ Map.lookupLE (unsafeNoAssertMakeUnslicedKey k) icTieBreaker
PageNo !i3 = max i1 i2 -- Post: the intersection of @[i1, i]@ and @[i2, i].
Expand Down

0 comments on commit 181e2b8

Please sign in to comment.