From 7f79b570e98378acec432e0d193a921317169c15 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 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",