Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault if gallopingSearchLeftPBounds is used with too large u #33

Open
nh2 opened this issue Apr 11, 2021 · 1 comment
Open

Segfault if gallopingSearchLeftPBounds is used with too large u #33

nh2 opened this issue Apr 11, 2021 · 1 comment

Comments

@nh2
Copy link

nh2 commented Apr 11, 2021

This illegal use of gallopingSearchLeftPBounds segfaults in ghci 8.6.5:

import           Data.Vector.Algorithms.Search (binarySearchP, gallopingSearchLeftPBounds, binarySearch)
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector as V

v <- V.thaw $ V.fromList [1,2,3]

gallopingSearchLeftPBounds (2 <) v 0 10

Note I give u = 10 when the maximum allowed values is 3 for the vector [1,2,3].

So it's expected that it fails.

However, a segfault is not expected, because I compile with default flags boundschecks = Enabled, and I the function doesn't have unsafe in the name or the docs, so I would expect a bounds check to happen.

@erikd
Copy link
Owner

erikd commented Apr 11, 2021

What would you suggest as a solution?

After a rudimentary examination of the issue, one solution is:

  • If the upper bound is greater than the length of the vector, simply return u
  • If the lower bound is less than the length of the vector, simply return '`l'

Would that work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants