diff options
author | luigi1111 <luigi1111w@gmail.com> | 2020-03-09 13:26:26 -0400 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2020-03-09 13:26:26 -0400 |
commit | 26107dc4cd9a55dcd3676781a96fe3d91c549596 (patch) | |
tree | 871792866eddbd8faa402a86d056114749a79dcb | |
parent | Merge pull request #6156 (diff) | |
parent | Fixed string_ref usage bug in epee::from_hex::vector (diff) | |
download | monero-26107dc4cd9a55dcd3676781a96fe3d91c549596.tar.xz |
Merge pull request #6360
533d85d Fixed string_ref usage bug in epee::from_hex::vector (vtnerd)
-rw-r--r-- | contrib/epee/src/hex.cpp | 8 | ||||
-rw-r--r-- | tests/unit_tests/epee_utils.cpp | 3 |
2 files changed, 7 insertions, 4 deletions
diff --git a/contrib/epee/src/hex.cpp b/contrib/epee/src/hex.cpp index 558983f7e..b654a0269 100644 --- a/contrib/epee/src/hex.cpp +++ b/contrib/epee/src/hex.cpp @@ -84,7 +84,7 @@ namespace epee return write_hex(out, src); } - std::vector<uint8_t> from_hex::vector(boost::string_ref src) + std::vector<uint8_t> from_hex::vector(const boost::string_ref src) { // should we include a specific character auto include = [](char input) { @@ -104,7 +104,7 @@ namespace epee result.reserve(count / 2); // the data to work with (std::string is always null-terminated) - auto data = src.data(); + auto data = src.begin(); // convert a single hex character to an unsigned integer auto char_to_int = [](const char *input) { @@ -130,9 +130,9 @@ namespace epee }; // keep going until we reach the end - while (data[0] != '\0') { + while (data != src.end()) { // skip unwanted characters - if (!include(data[0])) { + if (!include(*data)) { ++data; continue; } diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp index 6f887afda..a4b339295 100644 --- a/tests/unit_tests/epee_utils.cpp +++ b/tests/unit_tests/epee_utils.cpp @@ -840,6 +840,9 @@ TEST(FromHex, String) // decoding it this way also, ignoring spaces and colons between the numbers hex.assign("00:ff 0f:f0"); EXPECT_EQ(source, epee::from_hex::vector(hex)); + + hex.append("f0"); + EXPECT_EQ(source, epee::from_hex::vector(boost::string_ref{hex.data(), hex.size() - 2})); } TEST(ToHex, Array) |