Skip to content

Fix UsedWays bounds check#903

Open
Symmetricity wants to merge 1 commit into
systemed:masterfrom
Symmetricity:fix/usedways-bounds-check
Open

Fix UsedWays bounds check#903
Symmetricity wants to merge 1 commit into
systemed:masterfrom
Symmetricity:fix/usedways-bounds-check

Conversation

@Symmetricity
Copy link
Copy Markdown
Contributor

This PR is AI generated.

Summary

  • fixes UsedWays bounds checks when the requested way id is exactly the
    current usedList.size()
  • adds a small regression test for the first insert and exact-size growth cases

Background

UsedWays stores relation-used way ids in a std::vector<bool>. Its existing
checks used wayid > usedList.size(), then indexed usedList[wayid]. When
wayid == usedList.size(), that is one past the end of the vector.

That can produce undefined behavior in both directions:

  • insert() can write past the end instead of growing the vector first
  • at() can read past the end instead of returning false

I checked the history around this code. The surrounding UsedWays storage was
introduced for memory savings, and later retained during relation-processing
changes, but I did not find a rationale for treating the exact-size boundary as
valid.

Change

Use >= for the resize/read boundary so the vector grows before an exact-end
write, and exact-end reads are reported as absent.

This keeps the existing growth strategy and data structure unchanged.

Expected Behavior

There should be no intended output change except avoiding undefined behavior at
the vector boundary. The exact-boundary case now grows by the same +256
increment that nearby out-of-range ids already used.

Testing

  • git diff --check
  • make test_osm_store
  • RelWithDebInfo CMake configure/build
  • ctest --output-on-failure (no CMake tests are registered in this repo)

UsedWays stores relation-used way ids in a vector<bool>. The old exact-size check treated wayid == size() as valid and then indexed one past the vector.

Resize when the requested id is equal to the current size, and treat the same boundary as absent when reading. Add coverage for the first and exact-size insert cases.

Co-authored-by: Codex <noreply@openai.com>
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.

1 participant