From 0cde65f5a1ccc7f18074cb8ede32f702b0256802 Mon Sep 17 00:00:00 2001 From: Steffen Gaisser Date: Tue, 15 Jun 2021 15:33:52 +0200 Subject: [PATCH] Added some precautions in DHB::replyToReply --- devicehandlers/DeviceHandlerBase.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 2a3f9d661..5665b101b 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -591,9 +591,20 @@ void DeviceHandlerBase::replyToReply(const DeviceCommandId_t command, DeviceRepl //Is most likely periodic reply. Silent return. return; } - // Check if more replies are expected. If so, do nothing. DeviceCommandInfo* info = &replyInfo.command->second; - if (--info->expectedReplies == 0) { + if (info == nullptr){ + printWarningOrError(sif::OutputTypes::OUT_ERROR, + "replyToReply", HasReturnvaluesIF::RETURN_FAILED, + "Command pointer not found"); + return; + } + + if (info->expectedReplies > 0){ + // Check before to avoid underflow + info->expectedReplies--; + } + // Check if more replies are expected. If so, do nothing. + if (info->expectedReplies == 0) { // Check if it was transition or internal command. // Don't send any replies in that case. if (info->sendReplyTo != NO_COMMANDER) {