Skip to content

Commit

Permalink
Fix nilaway error in grid
Browse files Browse the repository at this point in the history
handlers/grid.go:110:12: error: Potential nil panic detected. Observed nil flow from source to dereference point:
        - handlers/grid.go:110:12: unassigned variable `imagesWH` sliced into

handlers/grid.go:123:16: error: Potential nil panic detected. Observed nil flow from source to dereference point:
        - handlers/grid.go:123:16: unassigned variable `heightRows` sliced into
  • Loading branch information
Wikidepia committed Aug 14, 2024
1 parent d1d6855 commit db73216
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions handlers/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func GenerateGrid(images []image.Image) (image.Image, error) {
var heightRows []int
// Calculate height of each row and canvas height
for i := 1; i < len(path); i++ {
if len(imagesWH) < path[i-1] {
return nil, errors.New("imagesWH is not long enough")
}
rowWH := imagesWH[path[i-1]:path[i]]

rowHeight := int(getHeight(rowWH, canvasWidth))
Expand All @@ -120,6 +123,9 @@ func GenerateGrid(images []image.Image) (image.Image, error) {
for i := 1; i < len(path); i++ {
inRow := images[path[i-1]:path[i]]
oldImWidth := 0
if len(heightRows) < i {
return nil, errors.New("heightRows is not long enough")
}
heightRow := heightRows[i-1]
for _, imageOne := range inRow {
newWidth := float64(heightRow) * float64(imageOne.Bounds().Dx()) / float64(imageOne.Bounds().Dy())
Expand Down

0 comments on commit db73216

Please sign in to comment.