Skip to content

Commit 49c6099

Browse files
committed
Add null pointer checks for gc9a01Display->updateRedrawTime() calls
Prevent potential null pointer dereference crashes when GC9A01 display usermod is not found or fails to initialize. The gc9a01Display pointer can be null (as shown in setup() where it logs 'GC9A01 display NOT FOUND'), so all calls to updateRedrawTime() must be guarded with null checks. Fixed 10 locations where updateRedrawTime() was called without checking if gc9a01Display is non-null.
1 parent 0c9c80f commit 49c6099

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

usermods/usermod_v2_rotary_encoder_ui_ALT/usermod_v2_rotary_encoder_ui_ALT.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ void RotaryEncoderUIUsermod::changeBrightness(bool increase) {
825825
// Throw away wake up input
826826
return;
827827
}
828-
gc9a01Display->updateRedrawTime();
828+
if (gc9a01Display) gc9a01Display->updateRedrawTime();
829829
#endif
830830

831831
//bri = max(min((increase ? bri+fadeAmount : bri-fadeAmount), 255), 0);
@@ -869,7 +869,7 @@ void RotaryEncoderUIUsermod::changeEffect(bool increase) {
869869
// Throw away wake up input
870870
return;
871871
}
872-
gc9a01Display->updateRedrawTime();
872+
if (gc9a01Display) gc9a01Display->updateRedrawTime();
873873
#endif
874874
effectCurrentIndex = max(min((increase ? effectCurrentIndex+1 : effectCurrentIndex-1), strip.getModeCount()-1), 0);
875875
effectCurrent = modes_alpha_indexes[effectCurrentIndex];
@@ -907,7 +907,7 @@ void RotaryEncoderUIUsermod::changeEffectSpeed(bool increase) {
907907
// Throw away wake up input
908908
return;
909909
}
910-
gc9a01Display->updateRedrawTime();
910+
if (gc9a01Display) gc9a01Display->updateRedrawTime();
911911
#endif
912912

913913
effectSpeed = max(min((increase ? effectSpeed+fadeAmount : effectSpeed-fadeAmount), 255), 0);
@@ -951,7 +951,7 @@ void RotaryEncoderUIUsermod::changeEffectIntensity(bool increase) {
951951
// Throw away wake up input
952952
return;
953953
}
954-
gc9a01Display->updateRedrawTime();
954+
if (gc9a01Display) gc9a01Display->updateRedrawTime();
955955
#endif
956956

957957
effectIntensity = max(min((increase ? effectIntensity+fadeAmount : effectIntensity-fadeAmount), 255), 0);
@@ -996,7 +996,7 @@ void RotaryEncoderUIUsermod::changeCustom(uint8_t par, bool increase) {
996996
// Throw away wake up input
997997
return;
998998
}
999-
gc9a01Display->updateRedrawTime();
999+
if (gc9a01Display) gc9a01Display->updateRedrawTime();
10001000
#endif
10011001

10021002
stateChanged = true;
@@ -1058,7 +1058,7 @@ void RotaryEncoderUIUsermod::changePalette(bool increase) {
10581058
// Throw away wake up input
10591059
return;
10601060
}
1061-
gc9a01Display->updateRedrawTime();
1061+
if (gc9a01Display) gc9a01Display->updateRedrawTime();
10621062
#endif
10631063

10641064
effectPaletteIndex = max(min((int)(increase ? effectPaletteIndex+1 : effectPaletteIndex-1), (int)(getPaletteCount()-1)), 0);
@@ -1103,7 +1103,7 @@ void RotaryEncoderUIUsermod::changeHue(bool increase){
11031103
// Throw away wake up input
11041104
return;
11051105
}
1106-
gc9a01Display->updateRedrawTime();
1106+
if (gc9a01Display) gc9a01Display->updateRedrawTime();
11071107
#endif
11081108

11091109
currentHue1 = max(min((increase ? currentHue1+fadeAmount : currentHue1-fadeAmount), 255), 0);
@@ -1151,7 +1151,7 @@ void RotaryEncoderUIUsermod::changeSat(bool increase){
11511151
// Throw away wake up input
11521152
return;
11531153
}
1154-
gc9a01Display->updateRedrawTime();
1154+
if (gc9a01Display) gc9a01Display->updateRedrawTime();
11551155
#endif
11561156

11571157
currentSat1 = max(min((increase ? currentSat1+fadeAmount : currentSat1-fadeAmount), 255), 0);
@@ -1198,7 +1198,7 @@ void RotaryEncoderUIUsermod::changePreset(bool increase) {
11981198
// Throw away wake up input
11991199
return;
12001200
}
1201-
gc9a01Display->updateRedrawTime();
1201+
if (gc9a01Display) gc9a01Display->updateRedrawTime();
12021202
#endif
12031203

12041204
if (presetHigh && presetLow && presetHigh > presetLow) {
@@ -1248,7 +1248,7 @@ void RotaryEncoderUIUsermod::changeCCT(bool increase){
12481248
// Throw away wake up input
12491249
return;
12501250
}
1251-
gc9a01Display->updateRedrawTime();
1251+
if (gc9a01Display) gc9a01Display->updateRedrawTime();
12521252
#endif
12531253

12541254
currentCCT = max(min((increase ? currentCCT+fadeAmount : currentCCT-fadeAmount), 255), 0);

0 commit comments

Comments
 (0)