mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
## Summary This PR refactors the `Buffer.concat` implementation to use modern C++ spans for safer memory operations and adds proper error handling for oversized buffers. ## Changes - **Use spans instead of raw pointers**: Replaced pointer arithmetic with `typedSpan()` and `span()` methods for safer memory access - **Add MAX_ARRAY_BUFFER_SIZE check**: Added explicit check with a descriptive error message when attempting to create buffers larger than JavaScriptCore's limit (4GB) - **Improve loop logic**: Changed loop counter from `int` to `size_t` and simplified the iteration using span sizes - **Enhanced test coverage**: Updated tests to verify the new error message and added comprehensive test cases for various Buffer.concat scenarios ## Test Plan All existing tests pass, plus added new tests: - ✅ Error handling for oversized buffers - ✅ Normal buffer concatenation - ✅ totalLength parameter handling (exact, larger, smaller) - ✅ Empty array handling - ✅ Single buffer handling ```bash ./build/debug/bun-debug test test/js/node/buffer-concat.test.ts # Result: 6 pass, 0 fail ``` 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2.0 KiB
2.0 KiB