From 32a53e1f3755960b09fc228dce23885aa7efcb8f Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Tue, 27 Aug 2019 14:03:49 -0700 Subject: =?UTF-8?q?[vcpkg]=20fix=20bug=20in=20StringView::operator=3D=3D?= =?UTF-8?q?=20=F0=9F=98=B1=20(#7930)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, `lhs == rhs` missed the check for `lhs.size() == rhs.size()`, and then did a `memcmp` on the buffers up to `lhs.size()`. This means that, if `lhs.size() < rhs.size()`, it would allow two unequal strings to compare equal if, up to `lhs.size()` they are the same; and if `lhs.size() > rhs.size()`, then it would read out of bounds. --- toolsrc/src/vcpkg-test/stringview.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 toolsrc/src/vcpkg-test/stringview.cpp (limited to 'toolsrc/src/vcpkg-test/stringview.cpp') diff --git a/toolsrc/src/vcpkg-test/stringview.cpp b/toolsrc/src/vcpkg-test/stringview.cpp new file mode 100644 index 000000000..4df8e6be5 --- /dev/null +++ b/toolsrc/src/vcpkg-test/stringview.cpp @@ -0,0 +1,17 @@ +#include + +#include + +template +static vcpkg::StringView sv(const char (&cstr)[N]) { + return cstr; +} + +TEST_CASE("string view operator==", "[stringview]") { + // these are due to a bug in operator== + // see commit 782723959399a1a0725ac49 + REQUIRE(sv("hey") != sv("heys")); + REQUIRE(sv("heys") != sv("hey")); + REQUIRE(sv("hey") == sv("hey")); + REQUIRE(sv("hey") != sv("hex")); +} -- cgit v1.2.3