From 1087736737b0dda2dcf581fb661be684030a9153 Mon Sep 17 00:00:00 2001 From: Sundar2629 <91921152+Sundar2629@users.noreply.github.com> Date: Tue, 16 Nov 2021 07:32:33 -0800 Subject: [PATCH] Fix data types (#11763) * Fix data types *std::min is a template requiring identical data types, so explicitly specify the datatype. *Fix signed vs unsigned bitwise operation. * Update src/transport/FabricTable.h Co-authored-by: Tennessee Carmel-Veilleux * Restyled by clang-format Co-authored-by: Tennessee Carmel-Veilleux Co-authored-by: Restyled.io --- src/lib/support/CHIPArgParser.cpp | 4 ++-- src/transport/FabricTable.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/support/CHIPArgParser.cpp b/src/lib/support/CHIPArgParser.cpp index 7618bcdcdfae87..a4384ba55fb2df 100644 --- a/src/lib/support/CHIPArgParser.cpp +++ b/src/lib/support/CHIPArgParser.cpp @@ -911,9 +911,9 @@ bool ParseInt(const char * str, int16_t & output) const int base = 10; int32_t output32 = 0; - if ((ParseInt(str, output32, base)) && (output32 <= SHRT_MAX)) + if ((ParseInt(str, output32, base)) && (output32 <= SHRT_MAX && output32 >= SHRT_MIN)) { - output = static_cast(UINT16_MAX & output32); + output = static_cast(output32); return true; } diff --git a/src/transport/FabricTable.h b/src/transport/FabricTable.h index 600e92497d560f..4d29521e13547f 100644 --- a/src/transport/FabricTable.h +++ b/src/transport/FabricTable.h @@ -41,7 +41,7 @@ namespace chip { static constexpr FabricIndex kMinValidFabricIndex = 1; -static constexpr FabricIndex kMaxValidFabricIndex = std::min(UINT8_MAX, CHIP_CONFIG_MAX_DEVICE_ADMINS); +static constexpr FabricIndex kMaxValidFabricIndex = std::min(UINT8_MAX - 1, CHIP_CONFIG_MAX_DEVICE_ADMINS); static constexpr uint8_t kFabricLabelMaxLengthInBytes = 32; // KVS store is sensitive to length of key strings, based on the underlying