Skip to content

Commit c0875d1

Browse files
tniessenjuanarbol
authored andcommitted
src: avoid casting std::trunc(... / ...) to size_t
Given that the divisor is not zero, the result of dividing unsigned integers is an unsigned integer that is always rounded down, i.e., there is no need to call std::trunc(). Doing so unnecessarily yields a floating-point number, requiring the result to be cast to an unsigned integer again. PR-URL: #44467 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 8f3ed25 commit c0875d1

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/crypto/crypto_keygen.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ Maybe<bool> SecretKeyGenTraits::AdditionalConfig(
6565
SecretKeyGenConfig* params) {
6666
Environment* env = Environment::GetCurrent(args);
6767
CHECK(args[*offset]->IsUint32());
68-
params->length = static_cast<size_t>(
69-
std::trunc(args[*offset].As<Uint32>()->Value() / CHAR_BIT));
68+
params->length = args[*offset].As<Uint32>()->Value() / CHAR_BIT;
7069
if (params->length > INT_MAX) {
7170
THROW_ERR_OUT_OF_RANGE(env,
7271
"length must be less than or equal to %u bits",

0 commit comments

Comments
 (0)