Skip to content

fix(vector): refuse insert and resize_set past the element limit - #3769

Merged
BaseMax merged 2 commits into
mainfrom
fix/vector-count-limit
Nov 21, 2026
Merged

BaseMax merged 2 commits into
mainfrom
fix/vector-count-limit

Conversation

@BaseMax

@BaseMax BaseMax commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

After the Reserve overflow fix a vector can reach count INT_MAX through ResizeSet, and Insert then overflowed count + 1, skipped growing and wrote past the allocation.

Insert and ResizeSet now panic with a clear message at the limit, like Push. The other count + n sites in the file already go through these paths.

Test: tests/en/stdlib/vector_count_limit (ResizeSet to the limit, then Insert panics).

Summary by CodeRabbit

  • Bug Fixes
    • Vector resizing and insertion now stop with an error when an operation would exceed the supported element-count limit, before changing the vector.
    • Appending to a vector remains unchanged.

@BaseMax
BaseMax requested a review from a team as a code owner November 21, 2026 17:14
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

Vector.resize_set and Vector.insert now panic when their specified count-limit conditions apply. A regression test checks insertion after resizing to length 2147483646.

Changes: Vector count limit

Layer / File(s) Summary
Count-limit checks and regression test
std/collections/vector.salam, tests/en/stdlib/vector_count_limit.salam, tests/en/stdlib/vector_count_limit.exit
resize_set and non-append insert now panic at the specified limits. The test resizes a vector to 2147483646, inserts at index 0, and expects exit code 134.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • SalamLang/Salam#3765: Updates vector capacity growth and push behavior at INT_MAX, which is directly related to the element-limit checks in this change.

Suggested labels: tests

Suggested reviewers: bdadmehr0, erfangnu

Merge Risk: Moderate · up to c87d1

The new regression test for the vector count limit is likely to fail in the test runner because its expected output includes a stderr panic line, and it may also fail on Windows because of the abort exit status. The library change looks sound, but fix the test expectations before merging.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@BaseMax
BaseMax merged commit 65ac57a into main Nov 21, 2026
10 of 11 checks passed
@BaseMax
BaseMax deleted the fix/vector-count-limit branch November 21, 2026 17:17
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