Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
vicroms committed Aug 25, 2024
1 parent ba09333 commit 75992bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/vcpkg-test/metrics.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <vcpkg-test/util.h>

#include <vcpkg/metrics.h>
#include <vcpkg/base/system.deviceid.h>

#include <vcpkg/metrics.h>

#include <set>

using namespace vcpkg;
Expand Down Expand Up @@ -89,19 +90,20 @@ TEST_CASE ("user config parses multiple paragraphs ", "[metrics]")
CHECK(result.last_completed_survey == "survey");
}

TEST_CASE("device id", "[metrics]")
TEST_CASE ("device id", "[metrics]")
{
CHECK(validate_device_id("c5337d65-1e69-46e1-af76-bffc7b9ff40a"));

CHECK_FALSE(validate_device_id(""));
CHECK_FALSE(validate_device_id("nope"));
CHECK_FALSE(validate_device_id("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"));
CHECK_FALSE(validate_device_id("c5337d65:1e69:46e1:af76:bffc7b9ff40a "));
CHECK_FALSE(validate_device_id("c5337d65:1e69:46e1:af76:bffc7b9ff40a\r\n"));
CHECK_FALSE(validate_device_id("c5337d65:1e69:46e1:af76:bffc7b9ff40a"));
CHECK_FALSE(validate_device_id("c5337d65-1e69-46e1-af76-bffc7b9ff40a "));
CHECK_FALSE(validate_device_id("c5337d6--1e6--46e--af76--ffc7b9ff40a"));
CHECK_FALSE(validate_device_id("c5337d65-1e69-46e1-af76-bffc7b9ff4\r\n"));
CHECK_FALSE(validate_device_id("c5337d65-1e69-46e1-af76-bffc7b9ff4\0"));
CHECK_FALSE(validate_device_id("C5337D65-1E69-46E1-AF76-BFFC7b9ff40A"));
CHECK_FALSE(validate_device_id("z5337x65:1y69:46z1:xx76:mlno7p9qr40s"));
CHECK_FALSE(validate_device_id("{c5337d65-1e69-46e1-af76-bffc7b9ff40a}"));
CHECK_FALSE(validate_device_id("c5337d65:1e69:46e1:af76:bffc7b9ff40a"));
}

TEST_CASE ("user config to string", "[metrics]")
Expand Down
5 changes: 3 additions & 2 deletions src/vcpkg/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,9 @@ namespace vcpkg
case REG_SZ:
case REG_EXPAND_SZ:
// remove trailing nulls
while (!value->data.empty() && !(L'\0' != *reinterpret_cast<const wchar_t*>(
value->data.data() + value->data.size() - 2)))
while (
!value->data.empty() && value->data.size() >= 2 &&
!(L'\0' != *reinterpret_cast<const wchar_t*>(value->data.data() + value->data.size() - 2)))
{
value->data.pop_back();
value->data.pop_back();
Expand Down

0 comments on commit 75992bf

Please sign in to comment.