Skip to content

Commit

Permalink
src: avoid strcmp() with Utf8Value
Browse files Browse the repository at this point in the history
Having Utf8Value::operator==() without operator!=() is awkward in C++17,
so add the negated equality operator. Then, use either instead of
strcmp() where appropriate.

PR-URL: #47827
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
  • Loading branch information
tniessen authored and danielleadams committed Jul 6, 2023
1 parent 40abf1f commit 45e2a2f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/crypto/crypto_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,7 @@ void SecureContext::SetECDHCurve(const FunctionCallbackInfo<Value>& args) {

Utf8Value curve(env->isolate(), args[0]);

if (strcmp(*curve, "auto") != 0 &&
!SSL_CTX_set1_curves_list(sc->ctx_.get(), *curve)) {
if (curve != "auto" && !SSL_CTX_set1_curves_list(sc->ctx_.get(), *curve)) {
return THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Failed to set ECDH curve");
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/crypto/crypto_tls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1350,8 +1350,7 @@ unsigned int TLSWrap::PskServerCallback(

// Make sure there are no utf8 replacement symbols.
Utf8Value identity_utf8(env->isolate(), identity_str);
if (strcmp(*identity_utf8, identity) != 0)
return 0;
if (identity_utf8 != identity) return 0;

Local<Value> argv[] = {
identity_str,
Expand Down
2 changes: 1 addition & 1 deletion src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ static void PrintJavaScriptErrorProperties(JSONWriter* writer,
continue;
}
node::Utf8Value k(isolate, key);
if (!strcmp(*k, "stack") || !strcmp(*k, "message")) continue;
if (k == "stack" || k == "message") continue;
node::Utf8Value v(isolate, value_string);
writer->json_keyvalue(k.ToStringView(), v.ToStringView());
}
Expand Down
5 changes: 2 additions & 3 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,8 @@ class Utf8Value : public MaybeStackBuffer<char> {
public:
explicit Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> value);

inline bool operator==(const char* a) const {
return strcmp(out(), a) == 0;
}
inline bool operator==(const char* a) const { return strcmp(out(), a) == 0; }
inline bool operator!=(const char* a) const { return !(*this == a); }
};

class TwoByteValue : public MaybeStackBuffer<uint16_t> {
Expand Down

0 comments on commit 45e2a2f

Please sign in to comment.