mirror of
https://github.com/pbnjay/grate.git
synced 2024-12-13 13:58:27 +02:00
Fix index out of bounds panic
Sheet.Resize did not resize all old rows.
This commit is contained in:
parent
ebe430dc09
commit
a459175619
@ -21,6 +21,17 @@ type Sheet struct {
|
||||
// Resize the sheet for the number of rows and cols given.
|
||||
// Newly added cells default to blank.
|
||||
func (s *Sheet) Resize(rows, cols int) {
|
||||
for i := range s.Rows {
|
||||
if i > rows {
|
||||
break
|
||||
}
|
||||
n := cols - len(s.Rows[i])
|
||||
if n <= 0 {
|
||||
continue
|
||||
}
|
||||
s.Rows[i] = append(s.Rows[i], make([]Cell, n)...)
|
||||
}
|
||||
|
||||
if rows <= 0 {
|
||||
rows = 1
|
||||
}
|
||||
@ -34,11 +45,6 @@ func (s *Sheet) Resize(rows, cols int) {
|
||||
for rows >= len(s.Rows) {
|
||||
s.Rows = append(s.Rows, make([]Cell, cols))
|
||||
}
|
||||
|
||||
for i := 0; i < s.NumRows && len(s.Rows[i]) < cols; i++ {
|
||||
r2 := make([]Cell, cols-len(s.Rows[i]))
|
||||
s.Rows[i] = append(s.Rows[i], r2...)
|
||||
}
|
||||
}
|
||||
|
||||
// Put the value at the cell location given.
|
||||
|
Loading…
Reference in New Issue
Block a user