From 9a2cab4b5ed3ff98ad84968ce2760c73fc5bcbd9 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Wed, 29 May 2024 13:32:11 +0200 Subject: [PATCH] Fixed a Coverity warning --- src/util.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util.h b/src/util.h index 4ce5c64..12fd044 100644 --- a/src/util.h +++ b/src/util.h @@ -156,6 +156,9 @@ FORCEINLINE void writeVarint(T value, std::vector& out) writeVarint(value, [&out](uint8_t b) { out.emplace_back(b); }); } +template static FORCEINLINE bool out_of_range(uint64_t value) { return value > std::numeric_limits::max(); } +template<> FORCEINLINE bool out_of_range(uint64_t) { return false; } + template const uint8_t* readVarint(const uint8_t* data, const uint8_t* data_end, T& b) { @@ -177,7 +180,7 @@ const uint8_t* readVarint(const uint8_t* data, const uint8_t* data_end, T& b) k += 7; if ((cur_byte & 0x80) == 0) { - if (result > std::numeric_limits::max()) { + if (out_of_range(result)) { return nullptr; } b = static_cast(result);