-
Notifications
You must be signed in to change notification settings - Fork 145
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
undefined behaviour in kdtree_cpu.cpp caught by -fsanitize=undefined #16
Comments
@jefferis Thank you for chasing this down and the proposal for a fix. Yes using a constant of correct width seems the correct fix for this issue.
|
Is it possible to do this without relying on |
Incidentally should that be?
or even |
@jefferis Sorry. Yes absolutely no need for C++11 constexpr, this was just automatic code writing. Would you mind making a pull-request for that so it gets linked to this discussion? Thanks again! |
* should use an explicitly uint64 constant * simplest is to use ULL suffix (LLU is apparently standards compliant but not always supported) * this came up because the nabor R package wrapping libnabo threw a UBSAN error for points with dimension = 1 * closes norlab-ulaval#16
I have recently wrapped libnabo in a package for R (here, source here). Although the package was accepted for distribution by CRAN, it was quickly pointed out to me that there is at least one place in libnabo that appears to depend on undefined behaviour by the compiler. Specifically at line 245 in kdtree_cpu.cpp:
when the dimension of coordinates is
1
anddimBitCount=1
that will imply:which is not defined (but will evaluate to 2147483647 in most cases). Obviously
dim=0
will also give an error but that should never happen. I think that the fix is as simple as:but I am no expert, so I offer that for discussion rather than immediately as a pull request.
P.S. I had some trouble debugging this within the R package so I ended up making a small test program:
The text was updated successfully, but these errors were encountered: