Repository navigation
refactor(segment): drop a restart check that is always true - #286
Merged
Merged
Conversation
siracozmen01
commented
Nov 8, 2026
siracozmen01
left a comment
Contributor
Author
There was a problem hiding this comment.
Review at 401e27d: ready, once CI goes green. The claim holds for every input.
- One caller.
Restartis static, and the only call is inmuniSegmentIterator_FindBreaksAround(src/segment.c:650). Feed, the init calls andNextBreaknever reach it. - offset < length on that path. The function returns
muni_errorInvalidforoffset > cursor->length(line 627). It returnsmuni_errorStateunless the iterator holds its whole text:moreFollows, a pending byte, or a piece not starting at offset 0 (line 637). It returnsmuni_successforoffset == lengthbeforeRestart(line 642). SoRestartruns only withoffset < length, which also rules outlength == 0. - The empty last piece. An iterator fed in pieces has
cursor->offset != cursor->positiononce a piece after the first is fed, soFindBreaksAroundreturnsmuni_errorStatebefore any read. The end-of-text case, after an empty last piece or not, is theoffset == lengthreturn. Neither reachesRestart. - position <= offset.
Alignreturns eitheroffsetitself (a stray continuation byte) or astartthat only advances whilestart + size <= offset, soposition <= offset < length.CodePointAtthen gets at least one byte.Alignalready readtext[offset]before this change, under the same bound. - The comment states that reason, and the body has Problem, Change and Verification, and no column-0
name(line.
No findings.
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.
Problem
Restartinsrc/segment.c, whichmuniSegmentIterator_FindBreaksAroundcalls, guards its first read withposition < length. That test is never false: the public function returns before callingRestartwhen the offset is the length, so the offset is below it, andAligngives the start of the code point that holds the offset, which is at most the offset. Source coverage of every suite at 0c2c23a shows it true 1.78M times and false never. A condition no input can reach reads as if a caller could pass the end of the text here.Change
Restartreads the code point at the position unconditionally, and its comment says why one is always there.Verification
tools/check.sh prpasses.Closes #284