From 7346404e55f8ee705c48ecc67e28f20e248d96f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Thu, 1 Sep 2022 12:42:33 +0200 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. PR-URL: https://github.com/nodejs/node/pull/44467 Reviewed-By: Ben Noordhuis Reviewed-By: Filip Skokan Reviewed-By: Anna Henningsen --- 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 dbd015589b307f..8def58a5f10cd9 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",