Skip to content

Commit 8ca5a42

Browse files
committed
Reject zero maxSize in SessionPool instead of clamping to 1
Address review feedback: maxSize is size_t, so a non-positive check reduces to == 0 (and "<= 0" would be a tautological-comparison warning under -Wall). Rather than silently clamping an invalid 0 to 1, fail fast by throwing IoTDBException so the misuse surfaces at construction time.
1 parent 6e635c3 commit 8ca5a42

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

iotdb-client/client-cpp/src/main/SessionPool.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@ void PooledSession::reset() {
3131
SessionPool::SessionPool(std::string host, int rpcPort, std::string username, std::string password,
3232
size_t maxSize)
3333
: host_(std::move(host)), rpcPort_(rpcPort), username_(std::move(username)),
34-
password_(std::move(password)), maxSize_(maxSize == 0 ? 1 : maxSize) {}
34+
password_(std::move(password)), maxSize_(maxSize) {
35+
if (maxSize_ == 0) {
36+
throw IoTDBException("SessionPool maxSize must be greater than 0.");
37+
}
38+
}
3539

3640
SessionPool::SessionPool(std::vector<std::string> nodeUrls, std::string username,
3741
std::string password, size_t maxSize)
3842
: rpcPort_(AbstractSessionBuilder::DEFAULT_RPC_PORT), nodeUrls_(std::move(nodeUrls)),
39-
username_(std::move(username)), password_(std::move(password)),
40-
maxSize_(maxSize == 0 ? 1 : maxSize) {}
43+
username_(std::move(username)), password_(std::move(password)), maxSize_(maxSize) {
44+
if (maxSize_ == 0) {
45+
throw IoTDBException("SessionPool maxSize must be greater than 0.");
46+
}
47+
}
4148

4249
SessionPool::~SessionPool() {
4350
try {

0 commit comments

Comments
 (0)