diff --git a/tdutils/td/utils/Parser.h b/tdutils/td/utils/Parser.h index 09584ea2e..6ac1b7aee 100644 --- a/tdutils/td/utils/Parser.h +++ b/tdutils/td/utils/Parser.h @@ -160,11 +160,11 @@ class Parser { return status_; } - bool start_with(Slice prefix) { - if (prefix.size() + ptr_ > end_) { + bool start_with(Slice prefix) const { + if (prefix.size() > static_cast(end_ - ptr_)) { return false; } - return std::memcmp(prefix.begin(), ptr_, prefix.size()) == 0; + return prefix == Slice(ptr_, prefix.size()); } bool skip_start_with(Slice prefix) { diff --git a/tdutils/td/utils/UInt.h b/tdutils/td/utils/UInt.h index bf81a2e1c..60160df31 100644 --- a/tdutils/td/utils/UInt.h +++ b/tdutils/td/utils/UInt.h @@ -48,7 +48,7 @@ struct UInt { template bool operator==(const UInt &a, const UInt &b) { - return std::memcmp(a.raw, b.raw, sizeof(a.raw)) == 0; + return a.as_slice() == b.as_slice(); } template @@ -84,7 +84,7 @@ MutableSlice as_slice(UInt &value) { template bool operator<(const UInt &a, const UInt &b) { - return std::memcmp(a.raw, b.raw, sizeof(a.raw)) < 0; + return a.as_slice() < b.as_slice(); } using UInt128 = UInt<128>; diff --git a/tdutils/td/utils/find_boundary.cpp b/tdutils/td/utils/find_boundary.cpp index 539179343..9c47f3911 100644 --- a/tdutils/td/utils/find_boundary.cpp +++ b/tdutils/td/utils/find_boundary.cpp @@ -24,7 +24,7 @@ bool find_boundary(ChainBufferReader range, Slice boundary, size_t &already_read auto save_range = range.clone(); char x[MAX_BOUNDARY_LENGTH + 4]; range.advance(boundary.size(), {x, sizeof(x)}); - if (std::memcmp(x, boundary.data(), boundary.size()) == 0) { + if (Slice(x, boundary.size()) == boundary) { return true; }