Skip to content

Extremely long codes can cause underflow errors #12

Closed
@drinckes

Description

@drinckes

In a test C++ implementation, long codes were causing segmentation faults. This was due to the grid computation, where the size of the grid squares are computed in degrees latitude and degrees longitude. These start at 1/8000th of a degree, and with each step, divide by 4 (latitude) or 5 (longitude).

Fairly quickly these can get to the minimum values that can be represented as floats and cause underflow errors.

To avoid this happening, I propose to limit the length of OLC codes. This would avoid this problem while still allowing extremely precise codes. 16 digits gives roughly centimeter resolution, and with 32 digits the OLC area is only 7.86E-11 cm wide (this is in the order of a helium atom).

I don't think it matters a great deal what the limit is as long as we define one.

The changes required are:

  • To modify the isValid method to reject codes with more than 32 digits or with more than 24 digits after the separator
  • To limit the encode method to only return codes with a maximum of 32 digits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions