From 905b2c0148fabfc9cbe8e93a6beb6fbf6b12d538 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 13 Aug 2022 17:36:53 +0200 Subject: [PATCH] protect from NULL pointer deref in ESP32 code when no MAIN rmt cannel is present --- DCCWaveform.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 5499b04..ea3a970 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -250,19 +250,27 @@ void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repea { int ret; do { - if(isMainTrack) - ret = rmtMainChannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats); - else - ret = rmtProgChannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats); + if(isMainTrack) { + if (rmtMainChannel != NULL) + ret = rmtMainChannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats); + } else { + if (rmtProgChannel != NULL) + ret = rmtProgChannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats); + } } while(ret > 0); } } bool DCCWaveform::getPacketPending() { - if(isMainTrack) + if(isMainTrack) { + if (rmtMainChannel == NULL) + return true; return rmtMainChannel->busy(); - else + } else { + if (rmtProgChannel == NULL) + return true; return rmtProgChannel->busy(); + } } void IRAM_ATTR DCCWaveform::loop() { DCCACK::checkAck(progTrack.getResets());