From 3e558183b3b64872ea2e25dd158e79f91147fbf5 Mon Sep 17 00:00:00 2001 From: Kai Hermann Date: Thu, 14 Nov 2024 15:55:03 +0100 Subject: [PATCH] SlacSimulator initialize state with UNMATCHED (#963) This could publish an empty string on startup while an enum was expected, leading to failures when running EVerest with schema validation enabled remove default empty string from state_to_string enable -Werror=switch-enum for SlacSimulator module Signed-off-by: Kai-Uwe Hermann --- modules/simulation/SlacSimulator/CMakeLists.txt | 5 +++++ modules/simulation/SlacSimulator/ev/ev_slacImpl.hpp | 2 +- modules/simulation/SlacSimulator/evse/slacImpl.hpp | 2 +- modules/simulation/SlacSimulator/util/state.cpp | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/simulation/SlacSimulator/CMakeLists.txt b/modules/simulation/SlacSimulator/CMakeLists.txt index 7a884c9d58..f60f20c30e 100644 --- a/modules/simulation/SlacSimulator/CMakeLists.txt +++ b/modules/simulation/SlacSimulator/CMakeLists.txt @@ -9,6 +9,11 @@ ev_setup_cpp_module() # ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1 # insert your custom targets and additional config variables here +target_compile_options(${MODULE_NAME} + PRIVATE + -Wimplicit-fallthrough + -Werror=switch-enum +) # ev@bcc62523-e22b-41d7-ba2f-825b493a3c97:v1 target_sources(${MODULE_NAME} diff --git a/modules/simulation/SlacSimulator/ev/ev_slacImpl.hpp b/modules/simulation/SlacSimulator/ev/ev_slacImpl.hpp index a7569576f4..70851e76ab 100644 --- a/modules/simulation/SlacSimulator/ev/ev_slacImpl.hpp +++ b/modules/simulation/SlacSimulator/ev/ev_slacImpl.hpp @@ -52,7 +52,7 @@ class ev_slacImpl : public ev_slacImplBase { // ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1 // insert your private definitions here - util::State state; + util::State state{util::State::UNMATCHED}; // ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1 }; diff --git a/modules/simulation/SlacSimulator/evse/slacImpl.hpp b/modules/simulation/SlacSimulator/evse/slacImpl.hpp index 1de2d01165..bc8056daed 100644 --- a/modules/simulation/SlacSimulator/evse/slacImpl.hpp +++ b/modules/simulation/SlacSimulator/evse/slacImpl.hpp @@ -59,7 +59,7 @@ class slacImpl : public slacImplBase { void set_state_to_unmatched(); void set_state_to_matching(); - util::State state; + util::State state{util::State::UNMATCHED}; // ev@3370e4dd-95f4-47a9-aaec-ea76f34a66c9:v1 }; diff --git a/modules/simulation/SlacSimulator/util/state.cpp b/modules/simulation/SlacSimulator/util/state.cpp index 31299521eb..b221673506 100644 --- a/modules/simulation/SlacSimulator/util/state.cpp +++ b/modules/simulation/SlacSimulator/util/state.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Pionix GmbH and Contributors to EVerest #include "state.hpp" +#include #include namespace module::util { @@ -13,9 +14,8 @@ std::string state_to_string(State state) { return "MATCHING"; case State::MATCHED: return "MATCHED"; - default: - return ""; } + throw std::out_of_range("Could not convert State to string"); } } // namespace module::util