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 strcmp() with Utf8Value #47827

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/crypto/crypto_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,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 @@ -531,9 +531,8 @@ class Utf8Value : public MaybeStackBuffer<char> {
return std::string_view(out(), length());
}

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