diff options
| author | nicole mazzuca <mazzucan@outlook.com> | 2019-08-27 14:03:49 -0700 |
|---|---|---|
| committer | Curtis J Bezault <curtbezault@gmail.com> | 2019-08-27 14:03:49 -0700 |
| commit | 32a53e1f3755960b09fc228dce23885aa7efcb8f (patch) | |
| tree | 1d550e51549c9575102481c8b117a7b61e696791 /toolsrc/src/vcpkg-test/stringview.cpp | |
| parent | 0eb73051028d5ece1dd837171728fd62c82c1202 (diff) | |
| download | vcpkg-32a53e1f3755960b09fc228dce23885aa7efcb8f.tar.gz vcpkg-32a53e1f3755960b09fc228dce23885aa7efcb8f.zip | |
[vcpkg] fix bug in StringView::operator== 😱 (#7930)
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.
Diffstat (limited to 'toolsrc/src/vcpkg-test/stringview.cpp')
| -rw-r--r-- | toolsrc/src/vcpkg-test/stringview.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
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 <catch2/catch.hpp> + +#include <vcpkg/base/stringview.h> + +template <std::size_t N> +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")); +} |
