-
Notifications
You must be signed in to change notification settings - Fork 524
Add bounds checks for some base cell accesses #430
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
Add bounds checks for some base cell accesses #430
Conversation
Are you sure before and after are in the right order there? Every single benchmark improves slightly when I compare the two (fewer microseconds per iteration). You'd expect testing noise to vary up and down. |
I reran and got:
After
I would imagine it's being influenced by other things running on the computer. |
"Invalid resolution fails"); | ||
t_assert(H3_EXPORT(h3ToParent)(child, 15) == 0, | ||
"Invalid resolution fails"); | ||
t_assert(H3_EXPORT(h3ToParent)(child, 16) == 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be H3_NULL
?
src/h3lib/lib/h3Index.c
Outdated
*/ | ||
void _h3ToFaceIjk(H3Index h, FaceIJK* fijk) { | ||
int baseCell = H3_GET_BASE_CELL(h); | ||
if (baseCell < 0 || baseCell >= NUM_BASE_CELLS) { // aaa TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kill TODO?
As discussed offline, I think we should have a separate PR that's a bit more paranoid about protecting against segfaults in |
I'll approach that in a separate PR. I think as a longer term evolution, once we have a clearer error handling story at the public API level, we can propagate error codes within the library too and avoid some of the potentially duplicated checking of base cell validity. Right now that duplication is essentially required by the need to return error codes which is a bigger change for baseCells.c. |
Partial update of #423 with tests (thanks @alexey-milovidov). These fix potential crashes (segfault) or otherwise out of bounds reads. I did not port two of the checks in baseCells.c since I could not readily test them. They could be added in a future PR.
Benchmark results (release configuration, recent MacBook Pro)
Before
After
From the benchmarks, h3ToGeo, h3ToGeoBoundary, and kRing do not seem to be significantly impacted. I don't think we have a benchmarking setup that is capable of detecting very small changes in performance, but there is no large change.