Fix Lua error with decimal lane values in osrm-extract#7420
Merged
DennisOSRM merged 4 commits intomasterfrom Mar 21, 2026
Merged
Fix Lua error with decimal lane values in osrm-extract#7420DennisOSRM merged 4 commits intomasterfrom
DennisOSRM merged 4 commits intomasterfrom
Conversation
The error occurred because to_number_uint() was returning a Lua float even for integer values, but Sol2 binding requires exact integer type for std::uint8_t. Added math.tointeger() conversion to ensure proper integer type is passed to C++ code. Co-authored-by: DennisOSRM <1067895+DennisOSRM@users.noreply.github.com> Agent-Logs-Url: https://github.com/Project-OSRM/osrm-backend/sessions/f697d5b1-5923-449b-a1f3-8ade4d08c1e7
math.tointeger is only available in Lua 5.3+. Since to_number_uint already validates n % 1 == 0, math.floor(n) is equivalent and works on all versions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When processing OSM data with decimal lane values (e.g.,
lanes=2.5), osrm-extract crashes with:"not a numeric type that fits exactly an integer (number maybe has significant decimals)". This occurs because Sol2's strict type checking rejects Lua floats when C++ expectsstd::uint8_t.Changes
Modified
to_number_uint()inprofiles/lib/guidance.lua: Convert validated numbers to integer type usingmath.tointeger()before returning, ensuring Sol2 bindings accept the value forRoadClassification::num_lanesAdded
features/car/lanes.feature: Test coverage for valid integer values, invalid decimal values,lanes:forward/lanes:backwardtags, and edge cases (zero, negative, non-numeric)Technical Details
Even when
to_number_uint()validated thatn % 1 == 0, it returned a Lua number (double) rather than an integer. Sol2 requires exact type matches for C++ integer fields:Invalid lane counts are now silently ignored rather than crashing the extraction process.
Original prompt