mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
src: replace unreachable code with static_assert
This function divides an unsigned 32-bit integer by 8, effectively right-shifting it by three bits, so the result must be less than INT_MAX. Refs: https://github.com/nodejs/node/pull/46209 PR-URL: https://github.com/nodejs/node/pull/46250 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
1 parent
27c51243b5
commit
5ccf4efbf8
1 file changed
+4
-9
@@ -16,7 +16,6 @@ using v8::Int32;
|
||||
using v8::Just;
|
||||
using v8::Local;
|
||||
using v8::Maybe;
|
||||
using v8::Nothing;
|
||||
using v8::Object;
|
||||
using v8::Uint32;
|
||||
using v8::Value;
|
||||
@@ -62,15 +61,11 @@ Maybe<bool> SecretKeyGenTraits::AdditionalConfig(
|
||||
const FunctionCallbackInfo<Value>& args,
|
||||
unsigned int* offset,
|
||||
SecretKeyGenConfig* params) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
CHECK(args[*offset]->IsUint32());
|
||||
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",
|
||||
static_cast<uint64_t>(INT_MAX) * CHAR_BIT);
|
||||
return Nothing<bool>();
|
||||
}
|
||||
uint32_t bits = args[*offset].As<Uint32>()->Value();
|
||||
static_assert(std::numeric_limits<decltype(bits)>::max() / CHAR_BIT <=
|
||||
INT_MAX);
|
||||
params->length = bits / CHAR_BIT;
|
||||
*offset += 1;
|
||||
return Just(true);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user