Skip to content

Commit

Permalink
Fix cast
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Pryakhin <[email protected]>
  • Loading branch information
waldgange committed May 13, 2024
1 parent 4cca72a commit 9ff7aec
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/groups/mwc/mwcu/mwcu_safecast.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,15 @@ safeCast(FROM value)
const TO kMax = bsl::numeric_limits<TO>::max();
const TO kMin = bsl::numeric_limits<TO>::min();

BSLS_ASSERT(static_cast<long long unsigned>(value) >
static_cast<long long unsigned>(kMax));
BSLS_ASSERT(static_cast<long long int>(value) <
static_cast<long long int>(kMin));
if (value < FROM(0)) {
// 'value' is negative
BSLS_ASSERT(static_cast<long long int>(value) >=
static_cast<long long int>(kMin));
} else {
BSLS_ASSERT(static_cast<long long unsigned>(value) <=
static_cast<long long unsigned>(kMax));
}


return static_cast<TO>(value);
}
Expand Down

0 comments on commit 9ff7aec

Please sign in to comment.