Skip to content

Commit 340a9f8

Browse files
committed
better bugfix for seven-seg-reloaded
* only reject invalid ranges when array access will be actually performed * fixed another stupid pointer arithmetic error Hint: I AM NOT THE MAINTAINER of this usermod. I'm just fixing an obvious coding error without knowing what the usermod really does.
1 parent 81cec6a commit 340a9f8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

usermods/seven_segment_display_reloaded/usermod_seven_segment_reloaded.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class UsermodSSDR : public Usermod {
165165
void _showElements(String *map, int timevar, bool isColon, bool removeZero
166166

167167
) {
168-
if (!(*map).equals("") && !(*map) == NULL) {
168+
if ((map != nullptr) && (*map != nullptr) && !(*map).equals("")) {
169169
int length = String(timevar).length();
170170
bool addZero = false;
171171
if (length == 1) {
@@ -237,12 +237,12 @@ class UsermodSSDR : public Usermod {
237237

238238
void _setLeds(int lednr, int lastSeenLedNr, bool range, int countSegments, int number, bool colon) {
239239
if ((lednr < 0) || (lednr >= umSSDRLength)) return; // prevent array bounds violation
240-
if ((number < 0) || (countSegments < 0) || (lastSeenLedNr <0)) return; // prevent array out of range access
241240

241+
if (!(colon && umSSDRColonblink) && ((number < 0) || (countSegments < 0))) return;
242242
if ((colon && umSSDRColonblink) || umSSDRNumbers[number][countSegments]) {
243243

244244
if (range) {
245-
for(int i = lastSeenLedNr; i <= lednr; i++) {
245+
for(int i = max(0, lastSeenLedNr); i <= lednr; i++) {
246246
umSSDRMask[i] = true;
247247
}
248248
} else {

0 commit comments

Comments
 (0)