Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: avoid casting std::trunc(... / ...) to size_t #44467

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/crypto/crypto_keygen.cc
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: the comment in src/crypto/crypto_keygen.h is wrong, it says it's the number of bits, not bytes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've decided not to change that here but I've opened #44470 to change nits in this and another comment.

if (params->length > INT_MAX) {
THROW_ERR_OUT_OF_RANGE(env,
"length must be less than or equal to %u bits",
Expand Down