From 2c2f1d3db4dac366ae66e7dfa057e90a3b527de4 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Mon, 28 Oct 2019 12:23:56 +0100 Subject: [PATCH] st7789: fix index out of bounds error This commit adds the same check to the st7789 that also exists in the st7735. --- st7789/st7789.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/st7789/st7789.go b/st7789/st7789.go index 69e6ce1..c6d2450 100644 --- a/st7789/st7789.go +++ b/st7789/st7789.go @@ -194,12 +194,13 @@ func (d *Device) FillRectangleWithBuffer(x, y, width, height int16, buffer []col offset := int32(0) for k > 0 { for i := int32(0); i < d.batchLength; i++ { - - c565 := RGBATo565(buffer[offset+i]) - c1 := uint8(c565 >> 8) - c2 := uint8(c565) - data[i*2] = c1 - data[i*2+1] = c2 + if offset+i < int32(len(buffer)) { + c565 := RGBATo565(buffer[offset+i]) + c1 := uint8(c565 >> 8) + c2 := uint8(c565) + data[i*2] = c1 + data[i*2+1] = c2 + } } if k >= d.batchLength { d.Tx(data, false)