vaxis
created pr with
95.1
added 95.2
1: 37f44c1 ! 1: 7a2f7ff fix(vxfw/list): check if index is out of bounds
cmds
checkout latest patchset:
ssh pr.pico.sh print 95 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 95.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 95
Patchset
95.1
fix(vxfw/list): check if index is out of bounds
Eric Bower
2025-12-16T16:03:32ZSemantic diff summary
1 added,
1 modified,
0 signature changed,
0 removed
across 2 analyzed files
+37
-0
vxfw/surface_test.go
#
| ... | ... | @@ -0,0 +1,37 @@ | |
| 1 | + | package vxfw_test | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "testing" | |
| 5 | + | ||
| 6 | + | "git.sr.ht/~rockorager/vaxis" | |
| 7 | + | "git.sr.ht/~rockorager/vaxis/vxfw" | |
| 8 | + | ) | |
| 9 | + | ||
| 10 | + | func TestWriteCellBoundsCheck(t *testing.T) { | |
| 11 | + | // Create a surface where Size claims more cells than Buffer actually has. | |
| 12 | + | // This simulates the bug where Size and Buffer get out of sync. | |
| 13 | + | s := vxfw.Surface{ | |
| 14 | + | Size: vxfw.Size{ | |
| 15 | + | Width: 100, | |
| 16 | + | Height: 100, | |
| 17 | + | }, | |
| 18 | + | Buffer: make([]vaxis.Cell, 50), // Only 50 cells, but Size claims 10000 | |
| 19 | + | } | |
| 20 | + | ||
| 21 | + | cell := vaxis.Cell{ | |
| 22 | + | Character: vaxis.Character{ | |
| 23 | + | Grapheme: "x", | |
| 24 | + | Width: 1, | |
| 25 | + | }, | |
| 26 | + | } | |
| 27 | + | ||
| 28 | + | // This should not panic even though the index would be out of bounds | |
| 29 | + | // if we only checked against Size. | |
| 30 | + | s.WriteCell(99, 99, cell) // Would calculate index 9999, but Buffer only has 50 cells | |
| 31 | + | ||
| 32 | + | // Also test that valid writes still work | |
| 33 | + | s.WriteCell(0, 0, cell) | |
| 34 | + | if s.Buffer[0].Character.Grapheme != "x" { | |
| 35 | + | t.Errorf("expected cell at (0,0) to be written, got %q", s.Buffer[0].Character.Grapheme) | |
| 36 | + | } | |
| 37 | + | } |