Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8307a4b

Browse filesBrowse files
tniessenruyadorno
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 <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 312e10c commit 8307a4b
Copy full SHA for 8307a4b

File tree

Expand file treeCollapse file tree

1 file changed

+4
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-9
lines changed
Open diff view settings
Collapse file

‎src/crypto/crypto_keygen.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_keygen.cc
+4-9Lines changed: 4 additions & 9 deletions
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;
@@ -62,15 +61,11 @@ Maybe<bool> SecretKeyGenTraits::AdditionalConfig(
6261
const FunctionCallbackInfo<Value>& args,
6362
unsigned int* offset,
6463
SecretKeyGenConfig* params) {
65-
Environment* env = Environment::GetCurrent(args);
6664
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-
}
65+
uint32_t bits = args[*offset].As<Uint32>()->Value();
66+
static_assert(std::numeric_limits<decltype(bits)>::max() / CHAR_BIT <=
67+
INT_MAX);
68+
params->length = bits / CHAR_BIT;
7469
*offset += 1;
7570
return Just(true);
7671
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.