mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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 <info@bnoordhuis.nl> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
8f3ed25e08
commit
c0875d1f00
1 file changed
+1
-2
@@ -65,8 +65,7 @@ Maybe<bool> SecretKeyGenTraits::AdditionalConfig(
|
||||
SecretKeyGenConfig* params) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
CHECK(args[*offset]->IsUint32());
|
||||
params->length = static_cast<size_t>(
|
||||
std::trunc(args[*offset].As<Uint32>()->Value() / CHAR_BIT));
|
||||
params->length = args[*offset].As<Uint32>()->Value() / CHAR_BIT;
|
||||
if (params->length > INT_MAX) {
|
||||
THROW_ERR_OUT_OF_RANGE(env,
|
||||
"length must be less than or equal to %u bits",
|
||||
|
||||
Reference in new issue
Block a user