From 484d05d54b30775b5e65d0ed6c6ea080322d583d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Wed, 31 Aug 2022 21:49:12 +0000 Subject: [PATCH] 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. --- src/crypto/crypto_keygen.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/crypto/crypto_keygen.cc b/src/crypto/crypto_keygen.cc index e8f55806de6897..af489967144d32 100644 --- a/src/crypto/crypto_keygen.cc +++ b/src/crypto/crypto_keygen.cc @@ -65,8 +65,7 @@ Maybe SecretKeyGenTraits::AdditionalConfig( SecretKeyGenConfig* params) { Environment* env = Environment::GetCurrent(args); CHECK(args[*offset]->IsUint32()); - params->length = static_cast( - std::trunc(args[*offset].As()->Value() / CHAR_BIT)); + params->length = args[*offset].As()->Value() / CHAR_BIT; if (params->length > INT_MAX) { THROW_ERR_OUT_OF_RANGE(env, "length must be less than or equal to %u bits",