fixed panic when writing to zero-sized buffer
This commit is contained in:
parent
3e2be025b3
commit
e553da2c61
@ -42,7 +42,9 @@ func (b *Buffer[T]) y(y int) int {
|
|||||||
|
|
||||||
// Set sets the value at position (x,y) to c
|
// Set sets the value at position (x,y) to c
|
||||||
func (b *Buffer[T]) Set(x, y int, v T) {
|
func (b *Buffer[T]) Set(x, y int, v T) {
|
||||||
b.data[b.y(y)][b.x(x)] = v
|
if b.width >= 0 && b.height >= 0 {
|
||||||
|
b.data[b.y(y)][b.x(x)] = v
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the value at position (x,y)
|
// Get returns the value at position (x,y)
|
||||||
|
@ -17,3 +17,8 @@ func TestSub(t *testing.T) {
|
|||||||
fmt.Println(strings.Repeat("-", 10))
|
fmt.Println(strings.Repeat("-", 10))
|
||||||
fmt.Println(s)
|
fmt.Println(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSet(t *testing.T) {
|
||||||
|
b := NewBuffer(10, 10, ' ')
|
||||||
|
b.Set(11, 0, 'a')
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user