Skip to content

fix: clamp negative count in string repeat to prevent huge allocation#253

Merged
cs01 merged 2 commits intomainfrom
fix/string-repeat-negative
Mar 12, 2026
Merged

fix: clamp negative count in string repeat to prevent huge allocation#253
cs01 merged 2 commits intomainfrom
fix/string-repeat-negative

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 11, 2026

Summary

  • "abc".repeat(-1) previously passed the negative count directly to the allocation and loop, causing a huge GC_malloc_atomic call (negative wraps to large positive via sext)
  • Now clamps negative counts to 0, returning empty string — matches JS behavior (JS throws RangeError, but empty string is safer for a native compiler)

Test plan

  • New repeat-edge-cases.ts fixture: basic repeat, zero count, single repeat
  • npm run verify:quick passes

🤖 Generated with Claude Code

cs01 and others added 2 commits March 11, 2026 16:46
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cs01 cs01 merged commit 3621dee into main Mar 12, 2026
12 checks passed
@cs01 cs01 deleted the fix/string-repeat-negative branch March 12, 2026 05:35
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