-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Mark io target static variables as const to avoid race conditions #2557
Conversation
@@ -90,7 +90,7 @@ kj::Array<kj::byte> AsymmetricKeyCryptoKeyImpl::exportKeyExt( | |||
auto bio = OSSL_BIO_MEM(); | |||
|
|||
struct EncDetail { | |||
char* pass = &EMPTY_PASSPHRASE[0]; | |||
char* pass = const_cast<char*>(&EMPTY_PASSPHRASE[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't used const_cast before – let me know if this usage pattern is incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this case is ok since we don't expect anything to be written.
Also cleans up remaining instances of uninitialized variables in that target.
a6951dc
to
c65a65a
Compare
@@ -51,13 +50,57 @@ class SqliteDatabase { | |||
// expected. | |||
operator sqlite3*() { return db; } | |||
|
|||
// Class which regulates a SQL query, especially to control how queries created in JavaScript | |||
// application code are handled. | |||
class Regulator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler insisted on Regulator being defined before the static constexpr Regulator variable, so I moved the subclass inside.
}; | ||
|
||
InputGate(Hooks& hooks = Hooks::DEFAULT); | ||
InputGate(Hooks& hooks = const_cast<Hooks&>(Hooks::DEFAULT)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally any const_cast
should come with a comment saying why it's OK. In this case: "const_cast OK because the object has no members, it's just a vtable."
Also cleans up remaining instances of uninitialized variables in that target. Some trivial cases of static variables elsewhere are also cleaned up.