Skip to content

Commit cde3755

Browse files
tniessenjuanarbol
authored andcommitted
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: #46209 PR-URL: #46250 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 8582f99 commit cde3755

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/crypto/crypto_keygen.cc

+4-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ using v8::Int32;
1616
using v8::Just;
1717
using v8::Local;
1818
using v8::Maybe;
19-
using v8::Nothing;
2019
using v8::Object;
2120
using v8::Uint32;
2221
using v8::Value;
@@ -63,15 +62,11 @@ Maybe<bool> SecretKeyGenTraits::AdditionalConfig(
6362
const FunctionCallbackInfo<Value>& args,
6463
unsigned int* offset,
6564
SecretKeyGenConfig* params) {
66-
Environment* env = Environment::GetCurrent(args);
6765
CHECK(args[*offset]->IsUint32());
68-
params->length = args[*offset].As<Uint32>()->Value() / CHAR_BIT;
69-
if (params->length > INT_MAX) {
70-
THROW_ERR_OUT_OF_RANGE(env,
71-
"length must be less than or equal to %u bits",
72-
static_cast<uint64_t>(INT_MAX) * CHAR_BIT);
73-
return Nothing<bool>();
74-
}
66+
uint32_t bits = args[*offset].As<Uint32>()->Value();
67+
static_assert(std::numeric_limits<decltype(bits)>::max() / CHAR_BIT <=
68+
INT_MAX);
69+
params->length = bits / CHAR_BIT;
7570
*offset += 1;
7671
return Just(true);
7772
}

0 commit comments

Comments
 (0)