From 56b3ec6fb6e7db1941e8cc27ec624aa8a54880be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Kubern=C3=A1t?= Date: Mon, 16 Dec 2024 19:22:43 +0100 Subject: [PATCH] RpcValue: Cast bools to ints as 0 Casting bools to ints never makes sense. The reason I found is in the checkAlarms algorithm, where if you put a boolean as `value`, it could later be interpreted as a bitfield, because of this implicit conversion. It'll still do it now, but at least it won't result in `true` which will stop it from deducing invalid alarms. --- libshvchainpack/src/rpcvalue.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libshvchainpack/src/rpcvalue.cpp b/libshvchainpack/src/rpcvalue.cpp index cded85d9..5f3d2c36 100644 --- a/libshvchainpack/src/rpcvalue.cpp +++ b/libshvchainpack/src/rpcvalue.cpp @@ -355,8 +355,7 @@ ResultType impl_to_int(const RpcValue::VariantType& value) return std::visit([] (const auto& x) { using TypeX = std::remove_cvref_t; if constexpr (std::is_same() || - std::is_same() || - std::is_same()) { + std::is_same()) { return static_cast(x); } else if constexpr (std::is_same()) { return static_cast(convert_to_int(x)); @@ -370,7 +369,8 @@ ResultType impl_to_int(const RpcValue::VariantType& value) std::is_same>() || std::is_same>() || std::is_same>() || - std::is_same>()) { + std::is_same>() || + std::is_same()) { // Casting a bool to an int is prohibited. return ResultType{0}; } else { static_assert(not_implemented_for_type, "impl_to_int not implemented for this type");