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