fix(stdlib): return error instead of panicking on windows size 0 🪟#170
Merged
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
What
windows(seq, 0)panicked the VM instead of returning an error:The stdlib
windowsfunction tooklength: i64, cast it tousize, and passed it straight toslice::windows(length)— which panics when the size is0. Negative input was also wrong: it wrapped to a hugeusizeand silently returned[].The sibling
chunksfunction already handles both cases correctly (alength == 0guard plus ausizeparameter so negatives are rejected at argument conversion). This change bringswindowsin line.Changes
ndc_stdlib/src/sequence.rs:windowsnow takeslength: usizeand returns an error whenlength == 0. Negatives are now rejected at arg conversion (arg 1: expected a non-negative integer), matchingchunks.tests/functional/programs/900_bugs/bug0024_windows_zero_size.ndc: regression test asserting the gracefulwindow size must be non-zeroerror.Context
Found while hunting for a way to panic the pipeline (lexer → parser → analyser → compiler → VM). The existing token-stream fuzzer never reaches this code because it only generates the identifiers
a,b,c,x,f,g, so it never calls any stdlib function by name — the whole stdlib surface is outside its reach.Behaviour unchanged on the happy path:
windows([1,2,3,4], 2)→[[1,2],[2,3],[3,4]], and a too-short sequence still yields[].🤖