THRIFT-5355 Do not rely on compiler and check boundaries
Client: cpp
Patch: Triton <19377203+EnigmaTriton@users.noreply.github.com>
This closes #2305
diff --git a/lib/cpp/src/thrift/async/TConcurrentClientSyncInfo.cpp b/lib/cpp/src/thrift/async/TConcurrentClientSyncInfo.cpp
index 0dac524..7f1b1cc 100644
--- a/lib/cpp/src/thrift/async/TConcurrentClientSyncInfo.cpp
+++ b/lib/cpp/src/thrift/async/TConcurrentClientSyncInfo.cpp
@@ -184,7 +184,11 @@
throw apache::thrift::TApplicationException(
TApplicationException::BAD_SEQUENCE_ID,
"about to repeat a seqid");
- int32_t newSeqId = nextseqid_++;
+ int32_t newSeqId = nextseqid_;
+ if (nextseqid_ == (std::numeric_limits<int32_t>::max)())
+ nextseqid_ = (std::numeric_limits<int32_t>::min)();
+ else
+ ++nextseqid_;
seqidToMonitorMap_[newSeqId] = newMonitor_(seqidGuard);
return newSeqId;
}