Skip to content

Commit

Permalink
src: remove void casts for clear_error_on_return
Browse files Browse the repository at this point in the history
There are a number of void casts of clear_error_on_return which is a
usage of the RAII idiom. The ClearErrorOnReturn struct only has a
destructor and no constructor which I believe was an issue in GCC
prior to version 4.8.0, which lead to a unused variable warning.

I'm wondering if these cast could be removed since GCC 4.8.5 or newer
is required now. An alternative solution would be to add an empty
constructor which should work allowing the compiler to detect that a
variable is used only for its side-effects.

Not sure if this was the sole reason for having these casts but wanted
to bring it up just in case.

Refs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10416
PR-URL: #13669
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
danbev authored and addaleax committed Jun 21, 2017
1 parent c27ffad commit 5b3e5fa
Showing 1 changed file with 0 additions and 14 deletions.
14 changes: 0 additions & 14 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,6 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
SecureContext* sc;
ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder());
ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence compiler warning.

if (args.Length() != 1) {
return env->ThrowTypeError("CA certificate argument is mandatory");
Expand Down Expand Up @@ -806,7 +805,6 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
}

ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence compiler warning.

BIO *bio = LoadBIO(env, args[0]);
if (!bio)
Expand Down Expand Up @@ -872,7 +870,6 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) {
SecureContext* sc;
ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder());
ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence compiler warning.

if (!root_cert_store) {
root_cert_store = NewRootCertStore();
Expand Down Expand Up @@ -901,7 +898,6 @@ void SecureContext::SetCiphers(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder());
Environment* env = sc->env();
ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence compiler warning.

if (args.Length() != 1) {
return env->ThrowTypeError("Ciphers argument is mandatory");
Expand Down Expand Up @@ -948,7 +944,6 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&sc, args.This());
Environment* env = sc->env();
ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence compiler warning.

// Auto DH is not supported in openssl 1.0.1, so dhparam needs
// to be specified explicitly
Expand Down Expand Up @@ -1073,7 +1068,6 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) {
SecureContext* sc;
ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder());
ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence compiler warning.

if (args.Length() < 1) {
return env->ThrowTypeError("PFX certificate argument is mandatory");
Expand Down Expand Up @@ -1697,7 +1691,6 @@ void SSLWrap<Base>::GetPeerCertificate(
Environment* env = w->ssl_env();

ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence unused variable warning.

Local<Object> result;
Local<Object> info;
Expand Down Expand Up @@ -1894,7 +1887,6 @@ void SSLWrap<Base>::Renegotiate(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder());

ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence unused variable warning.

bool yes = SSL_renegotiate(w->ssl_) == 1;
args.GetReturnValue().Set(yes);
Expand Down Expand Up @@ -2644,7 +2636,6 @@ int Connection::HandleSSLError(const char* func,
ZeroStatus zs,
SyscallStatus ss) {
ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence unused variable warning.

if (rv > 0)
return rv;
Expand Down Expand Up @@ -4259,7 +4250,6 @@ void Sign::SignFinal(const FunctionCallbackInfo<Value>& args) {
md_value = new unsigned char[md_len];

ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence compiler warning.

Error err = sign->SignFinal(
buf,
Expand Down Expand Up @@ -4382,7 +4372,6 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem,
return kSignNotInitialised;

ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence compiler warning.

EVP_PKEY* pkey = nullptr;
BIO* bp = nullptr;
Expand Down Expand Up @@ -4614,7 +4603,6 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) {
size_t out_len = 0;

ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence compiler warning.

bool r = Cipher<operation, EVP_PKEY_cipher_init, EVP_PKEY_cipher>(
kbuf,
Expand Down Expand Up @@ -4922,7 +4910,6 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) {
}

ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence compiler warning.
BIGNUM* key = nullptr;

if (args.Length() == 0) {
Expand Down Expand Up @@ -6165,7 +6152,6 @@ void SetEngine(const FunctionCallbackInfo<Value>& args) {
unsigned int flags = args[1]->Uint32Value();

ClearErrorOnReturn clear_error_on_return;
(void) &clear_error_on_return; // Silence compiler warning.

const node::Utf8Value engine_id(env->isolate(), args[0]);
ENGINE* engine = ENGINE_by_id(*engine_id);
Expand Down

0 comments on commit 5b3e5fa

Please sign in to comment.