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, |
| */ | ||
| void _h3ToFaceIjk(H3Index h, FaceIJK* fijk) { | ||
| int baseCell = H3_GET_BASE_CELL(h); | ||
| if (baseCell < 0 || baseCell >= NUM_BASE_CELLS) { // aaa 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.