Skip to content

Commit 274c0f2

Browse files
tniessenMoLow
authored andcommittedJul 6, 2023
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 5f8aef4 commit 274c0f2

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
@@ -841,8 +841,7 @@ void SecureContext::SetECDHCurve(const FunctionCallbackInfo<Value>& args) {
841841

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

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

‎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
@@ -525,9 +525,8 @@ class Utf8Value : public MaybeStackBuffer<char> {
525525
public:
526526
explicit Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> value);
527527

528-
inline bool operator==(const char* a) const {
529-
return strcmp(out(), a) == 0;
530-
}
528+
inline bool operator==(const char* a) const { return strcmp(out(), a) == 0; }
529+
inline bool operator!=(const char* a) const { return !(*this == a); }
531530
};
532531

533532
class TwoByteValue : public MaybeStackBuffer<uint16_t> {

0 commit comments

Comments
 (0)