Commit 103a5af
* Fix crash on reverseIndex when yBase exceeds lines.count (#256)
The crash occurred because Buffer.clear() did not reset yBase to 0.
When switching between normal and alternate buffers, the stale yBase
value could cause buffer.y + buffer.yBase to exceed buffer.lines.count,
triggering an out-of-bounds access in reverseIndex() and scroll().
Changes:
- Buffer.swift: Add yBase = 0 to clear() to fix the root cause
- Terminal.swift: Add defensive bounds checks in reverseIndex() and
scroll() to prevent crashes if buffer state becomes invalid
- BufferTests.swift: Add 9 unit tests covering the bug and edge cases
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* Fix crash in cmdRestoreCursor when savedX/savedY are invalid
The function was restoring buffer.x and buffer.y from saved values
without bounds checking, causing abort() in Debug builds when savedX
or savedY became invalid after resize/scroll operations.
Fix: Clamp savedX and savedY to valid ranges before assignment:
- buffer.x = min(max(0, buffer.savedX), cols - 1)
- buffer.y = min(max(0, buffer.savedY), rows - 1)
This is the same class of bug as issue #256.
Added 3 tests for cursor restore clamping behavior.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 79af76d commit 103a5af
3 files changed
Lines changed: 416 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| 303 | + | |
303 | 304 | | |
304 | 305 | | |
305 | 306 | | |
306 | 307 | | |
307 | | - | |
| 308 | + | |
308 | 309 | | |
309 | 310 | | |
310 | 311 | | |
311 | 312 | | |
312 | | - | |
| 313 | + | |
313 | 314 | | |
314 | 315 | | |
315 | 316 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2493 | 2493 | | |
2494 | 2494 | | |
2495 | 2495 | | |
2496 | | - | |
2497 | | - | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
2498 | 2500 | | |
2499 | 2501 | | |
2500 | 2502 | | |
| |||
5021 | 5023 | | |
5022 | 5024 | | |
5023 | 5025 | | |
| 5026 | + | |
| 5027 | + | |
| 5028 | + | |
| 5029 | + | |
| 5030 | + | |
| 5031 | + | |
| 5032 | + | |
| 5033 | + | |
5024 | 5034 | | |
5025 | 5035 | | |
5026 | 5036 | | |
| |||
5435 | 5445 | | |
5436 | 5446 | | |
5437 | 5447 | | |
| 5448 | + | |
5438 | 5449 | | |
5439 | | - | |
| 5450 | + | |
| 5451 | + | |
| 5452 | + | |
| 5453 | + | |
| 5454 | + | |
| 5455 | + | |
| 5456 | + | |
| 5457 | + | |
| 5458 | + | |
5440 | 5459 | | |
5441 | 5460 | | |
5442 | | - | |
| 5461 | + | |
5443 | 5462 | | |
5444 | 5463 | | |
5445 | 5464 | | |
| |||
0 commit comments