Repository navigation
Conversation
|
|
||
| // Empty tokens (e.g. from consecutive, leading, or trailing delimiters) are | ||
| // skipped above but were still counted by count_tokens, so fewer entries get | ||
| // stored than slots were reserved for. Release the trailing unused storage | ||
| // and shrink to the number actually assigned, so size()/data()/operator[] | ||
| // never expose an uninitialized pointer entry. |
There was a problem hiding this comment.
I think the right patch would be to fix count_tokens, then. Or to fix the code here to allocate the right amount up front. We have to do two passes over the string regardless.
There was a problem hiding this comment.
Went with fixing count_tokens. It now skips empty tokens, so parse() reserves exactly the number of entries it stores and can return entry_count directly without any post-shrink. The second pass is unchanged, so no extra work over the string. Dropped the destroy/resize block from parse().
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9499 +/- ##
==========================================
- Coverage 71.11% 70.91% -0.21%
==========================================
Files 261 261
Lines 80229 80229
Branches 19551 19551
==========================================
- Hits 57058 56897 -161
- Misses 17374 17404 +30
- Partials 5797 5928 +131 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Note that the clang-tidy thing is a false positive, because is_empty returns true for nullptr. |
|
@abadams agreed, |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
StringTable::parse sizes and reports its result from count_tokens(), which counts every empty segment, but the fill loop skips empty tokens, so a string with consecutive, leading, or trailing delimiters leaves the trailing PointerTable slots unassigned; PointerTable allocates without zeroing, so size()/data()/operator[] then hand back uninitialized pointers. These reach the Vulkan driver through vk_create_instance (requested_layers.data() as ppEnabledLayerNames from HL_VK_LAYERS / VK_INSTANCE_LAYERS) and atoi() in the HL_VK_ALLOC_CONFIG path, where each is dereferenced. The fix releases the skipped trailing storage and shrinks the table to the number of tokens actually stored, returning that count, so no unassigned entry is ever exposed.
Verified with a poisoning allocator: before, parse("a::b", ":") returns 3 and entry [2] is 0xaaaa... (dereferencing it segfaults); after, it returns 2 with entries "a" and "b". Added a regression case to test/runtime/string_table.cpp covering leading/consecutive/trailing delimiters and an all-delimiter string.
AI tooling was used to help prepare this change.