8000 Fix segfault in `removeVertexNode` due to negative hash by isaacbrodsky · Pull Request #94 · uber/h3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix segfault in removeVertexNode due to negative hash #94

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

Merged
merged 1 commit into from
Jul 18, 2018

Conversation

isaacbrodsky
Copy link
Collaborator
@isaacbrodsky isaacbrodsky commented Jul 18, 2018

Fixes #92

The hash in _hashVertex produces out of range values if (vertex->lat + vertex->lon)
was negative, because it would produce a negative remainder (such as -1) and then cast it to
an unsigned integer type. This index would then cause a segfault.

testH3SetToLinkedGeo.c is also updated to not calloc a fixed size of 1.

…gned

The hash in `_hashVertex` produces out of range values if `(vertex->lat + vertex->lon)`
was negative, because it would produce a negative module (such as -1) and then cast it to
an unsigned integer type. This index would then cause a segfault.

testH3SetToLinkedGeo.c is also updated to not `calloc` a fixed size of 1.
@isaacbrodsky isaacbrodsky requested a review from nrabinowitz July 18, 2018 01:22
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 5ad0d4d on isaacbrodsky:h3settolinkedgeo-segfault into c05ce48 on uber:master.

@@ -29,130 +29,123 @@ H3Index* makeSet(char** hexes, int numHexes) {
BEGIN_TESTS(h3SetToLinkedGeo);

TEST(empty) {
LinkedGeoPolygon* polygon = calloc(1, sizeof(LinkedGeoPolygon));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh

Copy link
Collaborator
@nrabinowitz nrabinowitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@@ -29,130 +29,123 @@ H3Index* makeSet(char** hexes, int numHexes) {
BEGIN_TESTS(h3SetToLinkedGeo);

TEST(empty) {
LinkedGeoPolygon* polygon = calloc(1, sizeof(LinkedGeoPolygon));
LinkedGeoPolygon polygon;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -70,7 +70,7 @@ void destroyVertexGraph(VertexGraph* graph) {
uint32_t _hashVertex(const GeoCoord* vertex, int res, int numBuckets) {
// Simple hash: Take the sum of the lat and lon with a precision level
// determined by the resolution, converted to int, modulo bucket count.
return (uint32_t)fmod((vertex->lat + vertex->lon) * pow(10, 15 - res),
return (uint32_t)fmod(fabs((vertex->lat + vertex->lon) * pow(10, 15 - res)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These math functions can kill your performance. You should benchmark these changes. Also might be worth comparing to sip hash using (const char*) &vertex->lat as input. I wonder which is faster.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better would be to assign an index to the individual vertices, removing the need for floating point equality/hashing entirely.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - I'd suggest we don't focus on the performance in this diff (can't imagine that a single fabs call will make that big a difference), and come back to it when the vertex index mode change is implemented. I'll open an issue for that now.

@isaacbrodsky isaacbrodsky merged commit 70373d2 into uber:master Jul 18, 2018
@isaacbrodsky isaacbrodsky deleted the h3settolinkedgeo-segfault branch July 18, 2018 22:02
mrdvt92 pushed a commit to mrdvt92/h3 that referenced this pull request Jun 19, 2022
Fix segfault in `removeVertexNode` due to negative hash
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

Successfully merging this pull request may close these issues.

Segfault on h3SetToLinkedGeo for certain res 8 hexes
5 participants
0