Fixed string_ref usage bug in epee::from_hex::vector

This commit is contained in:
Lee Clagett 2020-02-28 17:42:28 -05:00 committed by wowario
parent 1ecb5046d2
commit 3068408d04
No known key found for this signature in database
GPG Key ID: 24DCBE762DE9C111
2 changed files with 7 additions and 4 deletions

View File

@ -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;
}

View File

@ -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)