Repository navigation
Conversation
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 17e42cc4 on Windows 11: test_zero_span_negative.py 4 OK, test_zero_span.py 3 OK; git diff --check clean.
Negative indices in the zero_span range helpers are normalized, and the existing range tests pass. No blocking issue.
|
Independent check of I also compared |
|
PASS. Minor: "wrap like the ISA" is really slice semantics, and it is only correct because both callers address through slices ( Approve. AI-assisted review, no game files, no GPU. |
|
@tupacfan04 — thanks, and I've taken the minor point: |
Claimed in the coordination issue as a new BUILD item: #4257 (comment).
What and why
tools/zero_span.pydocuments that its counts matchlen(buf[start:end])and thatall_zerois true only for an empty or all-zero slice. It clippedendtolen(buf)but never normalized negative indices the way Python slicing does, so those two guarantees broke for negative ranges:gap_split(b'ABCDEFGHIJ'*20, -5, 10)returned(0, 15)forbuf[-5:10], which is empty.gap_split(buf, -30, 200)returned 230 bytes for a 30-byte slice.all_zero(buf, 0, -5)returnedTruefor 195 non-zero bytes.Both helpers now normalize both endpoints with
slice(start, end).indices(len(buf)), which implements Python's own slice rules (negative indices, clamping and empty ranges).gap_splitkeeps the oldstart > end → 0 bytesbehavior viamax(0, end - start). Non-negative behavior is byte-for-byte unchanged.Scope: this is a correctness fix for the public helper; current in-tree callers pass non-negative stream offsets, so it is not a live scanner failure.
Tested
AI-assisted (OpenCode). Windows 11, Python 3.13.12, CPU only, no GPU and no game data.
tests/test_zero_span_negative.py(4 tests, parameterized over nine ranges and zero/non-zero buffers): 14 assertion failures on currentmain(03b09a08) and all pass on this branch.python -I tests/test_zero_span.py: 3 OK in 9.3 s on this branch (no regression, including the 48 MiB gap and all nine scanners).python -m compileall -q tools tests: clean.No file overlap with open PR #4021: that PR touches
tests/test_zero_span.py, while this one changestools/zero_span.pyand adds a separate test file.Checklist