From 03a7297cab6337a8a0b92d9a7dffa4874e5f4709 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 29 Apr 2026 13:36:09 +0200 Subject: [PATCH] DectrisSimplonClient: Avoid dereferencing null pointers in error handling --- detector_control/DectrisSimplonClient.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/detector_control/DectrisSimplonClient.cpp b/detector_control/DectrisSimplonClient.cpp index 552513e5..90ea7e39 100644 --- a/detector_control/DectrisSimplonClient.cpp +++ b/detector_control/DectrisSimplonClient.cpp @@ -54,10 +54,12 @@ void DectrisSimplonClient::SendDetectorCommand(SimplonDetectorCommand cmd) { auto res = cli_cmd.Post(addr); if (!res || res->status != httplib::StatusCode::OK_200) { - std::string err_msg = "Command failed " + key + "; HTTP " + std::to_string(res->status); - if (res && !res->body.empty()) - err_msg += "; " + res->body; - + std::string err_msg = "Command failed " + key; + if (res) { + err_msg += "; HTTP" + std::to_string(res->status); + if (!res->body.empty()) + err_msg += "; " + res->body; + } throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, err_msg); } } @@ -76,10 +78,12 @@ void DectrisSimplonClient::SetConfig(SimplonModule element, const std::string &k auto res = cli_cmd.Post(addr, j.dump(), "application/json"); if (!res || res->status != httplib::StatusCode::OK_200) { - std::string err_msg = "Configure failed " + key + "; HTTP " + std::to_string(res->status); - if (res && !res->body.empty()) - err_msg += "; " + res->body; - + std::string err_msg = "Configure failed " + key; + if (res) { + err_msg += "; HTTP" + std::to_string(res->status); + if (!res->body.empty()) + err_msg += "; " + res->body; + } throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, err_msg); } }