From db732162665c087a37d83f9cb32b14a719d34062 Mon Sep 17 00:00:00 2001 From: Akmal Date: Wed, 14 Aug 2024 15:19:14 +0700 Subject: [PATCH] Fix nilaway error in grid 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 --- handlers/grid.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/handlers/grid.go b/handlers/grid.go index 5559ff7..1b8fe2d 100644 --- a/handlers/grid.go +++ b/handlers/grid.go @@ -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)) @@ -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())