Skip to content

Commit 18b7208

Browse files
tniessenRafaelGSS
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 <info@bnoordhuis.nl> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 4331bbe commit 18b7208

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)