Skip to content

Commit 632c5b4

Browse files
committed
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
1 parent 671ffd7 commit 632c5b4

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/crypto/crypto_keygen.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,11 @@ Maybe<bool> SecretKeyGenTraits::AdditionalConfig(
6262
const FunctionCallbackInfo<Value>& args,
6363
unsigned int* offset,
6464
SecretKeyGenConfig* params) {
65-
Environment* env = Environment::GetCurrent(args);
6665
CHECK(args[*offset]->IsUint32());
67-
params->length = args[*offset].As<Uint32>()->Value() / CHAR_BIT;
68-
if (params->length > INT_MAX) {
69-
THROW_ERR_OUT_OF_RANGE(env,
70-
"length must be less than or equal to %u bits",
71-
static_cast<uint64_t>(INT_MAX) * CHAR_BIT);
72-
return Nothing<bool>();
73-
}
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;
7470
*offset += 1;
7571
return Just(true);
7672
}

0 commit comments

Comments
 (0)