From a3cb6b317284921ed18de7bef3c988b2eee7d248 Mon Sep 17 00:00:00 2001 From: Konrad Breitsprecher Date: Wed, 21 Oct 2026 14:13:31 +0200 Subject: [PATCH 1/2] lin: throw if SendDynamicResponse is called without InitDynamic ThrowIfNotDynamic checked the same condition as ThrowIfDynamic, so SendDynamicResponse on a controller that was not initialized with InitDynamic (or not initialized at all) was silently processed. Invert the check and throw SilKit::StateError, as documented in LinControllerExtensions.hpp. Co-Authored-By: Claude Opus 5.5 (1M context) Signed-off-by: Konrad Breitsprecher --- SilKit/source/services/lin/LinController.cpp | 9 +++------ .../services/lin/Test_LinControllerTrivialSim.cpp | 10 ++++++++++ docs/changelog/versions/latest.md | 4 +++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/SilKit/source/services/lin/LinController.cpp b/SilKit/source/services/lin/LinController.cpp index b96ff82c2..d0419c526 100644 --- a/SilKit/source/services/lin/LinController.cpp +++ b/SilKit/source/services/lin/LinController.cpp @@ -161,13 +161,13 @@ void LinController::ThrowIfDynamic(const std::string& callingMethodName) const void LinController::ThrowIfNotDynamic(const std::string& callingMethodName) const { - if (_useDynamicResponse) + if (!_useDynamicResponse) { std::string errorMsg = callingMethodName + " can only be called if the node was initialized using InitDynamic!"; _logger->MakeMessage(Logging::Level::Error, TopicOf(*this)) .SetMessage(errorMsg) .Dispatch(); - throw SilKitError{errorMsg}; + throw SilKit::StateError{errorMsg}; } } @@ -372,10 +372,7 @@ void LinController::InitDynamic(const SilKit::Experimental::Services::Lin::LinCo void LinController::SendDynamicResponse(const LinFrame& frame) { - if (!_useDynamicResponse) - { - ThrowIfNotDynamic(__FUNCTION__); - } + ThrowIfNotDynamic(__FUNCTION__); // prepare the response update LinFrameResponse response{}; diff --git a/SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp b/SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp index 2b0abb498..93819288b 100644 --- a/SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp +++ b/SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp @@ -811,6 +811,16 @@ TEST_F(Test_LinControllerTrivialSim, add_remove_handler) master.ReceiveMsg(&slave1, transmission); } +TEST_F(Test_LinControllerTrivialSim, send_dynamic_response_throws_if_not_dynamic) +{ + const auto frame = MakeFrame(17, LinChecksumModel::Enhanced, 4); + + EXPECT_THROW(master.SendDynamicResponse(frame), SilKit::StateError); + + master.Init(MakeControllerConfig(LinControllerMode::Master)); + EXPECT_THROW(master.SendDynamicResponse(frame), SilKit::StateError); +} + //////////// // Tracing //////////// diff --git a/docs/changelog/versions/latest.md b/docs/changelog/versions/latest.md index cc47f4d97..e4df93e85 100644 --- a/docs/changelog/versions/latest.md +++ b/docs/changelog/versions/latest.md @@ -1,3 +1,5 @@ # [5.0.9] - UNRELEASED -> This changelog entry is still empty. \ No newline at end of file +## Fixed + +- LIN: `SendDynamicResponse` now throws a `SilKit::StateError`, as documented, if the controller was not initialized using `InitDynamic`. Previously, the call was silently processed. From e4c4c4aab2d4159c9175077f88a76cd02b1025ac Mon Sep 17 00:00:00 2001 From: Konrad Breitsprecher Date: Thu, 22 Oct 2026 13:30:22 +0200 Subject: [PATCH 2/2] tests: describe the intention of the SendDynamicResponse test Co-Authored-By: Claude Opus 5.5 (1M context) Signed-off-by: Konrad Breitsprecher --- SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp b/SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp index 93819288b..bdfa65a51 100644 --- a/SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp +++ b/SilKit/source/services/lin/Test_LinControllerTrivialSim.cpp @@ -811,6 +811,8 @@ TEST_F(Test_LinControllerTrivialSim, add_remove_handler) master.ReceiveMsg(&slave1, transmission); } +// SendDynamicResponse throws a StateError if the controller was not initialized using InitDynamic, including when it +// was not initialized at all. TEST_F(Test_LinControllerTrivialSim, send_dynamic_response_throws_if_not_dynamic) { const auto frame = MakeFrame(17, LinChecksumModel::Enhanced, 4);