From d7397f93e4045d34a7ce175dc792460ff0e026cb Mon Sep 17 00:00:00 2001 From: Louis Cloete Date: Wed, 28 Jul 2021 12:34:51 +0200 Subject: [PATCH 1/3] Changed int32_t to int64_t to prevent overflow and crash with Digits > 10 --- src/GFX4d.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GFX4d.cpp b/src/GFX4d.cpp index e097a04..5ed69c9 100644 --- a/src/GFX4d.cpp +++ b/src/GFX4d.cpp @@ -1093,7 +1093,7 @@ void GFX4d::LedDigitsDisplay(int16_t newval, uint16_t index, int16_t Digits, int void GFX4d::LedDigitsDisplay(int16_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks, int16_t altx, int16_t alty) { int16_t i, k, lb; - int32_t l; + int64_t l; l = 1; for (i = 1; i < Digits; i++) l *= 10; From cdeffca647fcd9f4514048db16b0f754d606c2f4 Mon Sep 17 00:00:00 2001 From: Louis Cloete Date: Wed, 28 Jul 2021 13:08:47 +0200 Subject: [PATCH 2/3] Changed argument types as necessary to int64_t as well --- src/GFX4d.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/GFX4d.cpp b/src/GFX4d.cpp index 5ed69c9..f80f4a6 100644 --- a/src/GFX4d.cpp +++ b/src/GFX4d.cpp @@ -1042,14 +1042,15 @@ void GFX4d::UserImage(uint16_t ui, int altx, int alty) ScrollEnable(setemp); } -void GFX4d::LedDigitsDisplaySigned(int16_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks) +void GFX4d::LedDigitsDisplaySigned(int64_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks) { LedDigitsDisplaySigned(newval, index, Digits, MinDigits, WidthDigit, LeadingBlanks, 0x7fff , 0x7fff); } -void GFX4d::LedDigitsDisplaySigned(int16_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks, int16_t altx, int16_t alty) +void GFX4d::LedDigitsDisplaySigned(int64_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks, int16_t altx, int16_t alty) { - int16_t i, m, lstb, nv, digita[7]; + int16_t i, m, lstb, digita[7]; + int64_t nv; int leftpos = 0; nv = newval ; lstb = 1 ; @@ -1085,12 +1086,12 @@ void GFX4d::LedDigitsDisplaySigned(int16_t newval, uint16_t index, int16_t Digit } } -void GFX4d::LedDigitsDisplay(int16_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks) +void GFX4d::LedDigitsDisplay(int64_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks) { LedDigitsDisplay(newval, index, Digits, MinDigits, WidthDigit, LeadingBlanks, 0x7fff , 0x7fff); } -void GFX4d::LedDigitsDisplay(int16_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks, int16_t altx, int16_t alty) +void GFX4d::LedDigitsDisplay(int64_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks, int16_t altx, int16_t alty) { int16_t i, k, lb; int64_t l; From f685301b88a266c642a0db72bd45e8b9a3ff7ece Mon Sep 17 00:00:00 2001 From: Louis Cloete Date: Wed, 28 Jul 2021 13:14:46 +0200 Subject: [PATCH 3/3] changed function prototypes as well. --- src/GFX4d.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/GFX4d.h b/src/GFX4d.h index e21f8a6..7aacc0d 100644 --- a/src/GFX4d.h +++ b/src/GFX4d.h @@ -793,10 +793,10 @@ class GFX4d : public Print UserImages(uint16_t uis, int16_t frame, int offset, int16_t altx, int16_t alty), UserImages(uint16_t uisnb, int16_t framenb, int16_t newx, int16_t newy), UserImagesDR(uint16_t uino, int frames, int16_t uxpos, int16_t uypos, int16_t uwidth, int16_t uheight), - LedDigitsDisplay(int16_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks), - LedDigitsDisplay(int16_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks, int16_t altx, int16_t alty), - LedDigitsDisplaySigned(int16_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks), - LedDigitsDisplaySigned(int16_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks, int16_t altx, int16_t alty), + LedDigitsDisplay(int64_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks), + LedDigitsDisplay(int64_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks, int16_t altx, int16_t alty), + LedDigitsDisplaySigned(int64_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks), + LedDigitsDisplaySigned(int64_t newval, uint16_t index, int16_t Digits, int16_t MinDigits, int16_t WidthDigit, int16_t LeadingBlanks, int16_t altx, int16_t alty), DrawWidget(uint32_t Index, int16_t uix, int16_t uiy, int16_t uiw, int16_t uih, uint16_t frame, int16_t bar, bool images, uint8_t cdv), DrawImage(uint32_t Index, int16_t uix, int16_t uiy), UserCharacter(uint32_t *data, uint8_t ucsize, int16_t ucx, int16_t ucy, uint16_t color, uint16_t bgcolor),