Skip to content

Commit d2d5789

Browse files
authored
src: avoid strcmp() with Utf8Value
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>
1 parent d900912 commit d2d5789

File tree

4 files changed

+5
-8
lines changed

4 files changed

+5
-8
lines changed

src/crypto/crypto_context.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,7 @@ void SecureContext::SetECDHCurve(const FunctionCallbackInfo<Value>& args) {
840840

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

843-
if (strcmp(*curve, "auto") != 0 &&
844-
!SSL_CTX_set1_curves_list(sc->ctx_.get(), *curve)) {
843+
if (curve != "auto" && !SSL_CTX_set1_curves_list(sc->ctx_.get(), *curve)) {
845844
return THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Failed to set ECDH curve");
846845
}
847846
}

src/crypto/crypto_tls.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1350,8 +1350,7 @@ unsigned int TLSWrap::PskServerCallback(
13501350

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

13561355
Local<Value> argv[] = {
13571356
identity_str,

src/node_report.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ static void PrintJavaScriptErrorProperties(JSONWriter* writer,
401401
continue;
402402
}
403403
node::Utf8Value k(isolate, key);
404-
if (!strcmp(*k, "stack") || !strcmp(*k, "message")) continue;
404+
if (k == "stack" || k == "message") continue;
405405
node::Utf8Value v(isolate, value_string);
406406
writer->json_keyvalue(k.ToStringView(), v.ToStringView());
407407
}

src/util.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,8 @@ class Utf8Value : public MaybeStackBuffer<char> {
531531
return std::string_view(out(), length());
532532
}
533533

534-
inline bool operator==(const char* a) const {
535-
return strcmp(out(), a) == 0;
536-
}
534+
inline bool operator==(const char* a) const { return strcmp(out(), a) == 0; }
535+
inline bool operator!=(const char* a) const { return !(*this == a); }
537536
};
538537

539538
class TwoByteValue : public MaybeStackBuffer<uint16_t> {

0 commit comments

Comments
 (0)