diff --git a/hazelcast/src/hazelcast/client/client_impl.cpp b/hazelcast/src/hazelcast/client/client_impl.cpp index cee2e0ab7..f9eb3fbf5 100644 --- a/hazelcast/src/hazelcast/client/client_impl.cpp +++ b/hazelcast/src/hazelcast/client/client_impl.cpp @@ -758,7 +758,7 @@ twos_complement(std::vector& a) } // add 1 int8_t carry = 1; - for (auto i = a.size() - 1; i >= 0; i--) { + for (int i = static_cast(a.size()) - 1; i >= 0; i--) { a[i] = a[i] + carry; if (a[i] == 0) { carry = 1; diff --git a/hazelcast/test/src/HazelcastTests2.cpp b/hazelcast/test/src/HazelcastTests2.cpp index 186232bb2..1e704e0f8 100644 --- a/hazelcast/test/src/HazelcastTests2.cpp +++ b/hazelcast/test/src/HazelcastTests2.cpp @@ -140,6 +140,24 @@ TEST_F(DecimalTest, cascading_carry_bit_test) { -67, 19, -58, 119, -111, -77, 0, 0, 0 }); } +TEST_F(DecimalTest, twos_complement_single_byte_full_carry) +{ + // carry propagates out of the only byte; the signed loop index must exit + // cleanly + std::vector v = { 0 }; + pimpl::twos_complement(v); + ASSERT_EQ((std::vector{ 0 }), v); +} + +TEST_F(DecimalTest, twos_complement_multi_byte_full_carry) +{ + // carry propagates out of every byte; a size_t loop index would wrap to + // SIZE_MAX + std::vector v = { 0, 0, 0 }; + pimpl::twos_complement(v); + ASSERT_EQ((std::vector{ 0, 0, 0 }), v); +} + class AddressHelperTest : public ClientTest {};