diff --git a/contrib/epee/src/hex.cpp b/contrib/epee/src/hex.cpp index 1c6d236dc..4a8f093e0 100644 --- a/contrib/epee/src/hex.cpp +++ b/contrib/epee/src/hex.cpp @@ -134,7 +134,7 @@ namespace epee // should we include a specific character auto include = [](char input) { // we ignore spaces and colons - return !std::isspace(input) && input != ':'; + return !std::isspace(static_cast(input)) && input != ':'; }; // the number of relevant characters to decode @@ -153,7 +153,7 @@ namespace epee // convert a single hex character to an unsigned integer auto char_to_int = [](const char *input) { - switch (std::tolower(*input)) { + switch (std::tolower(static_cast(*input))) { case '0': return 0; case '1': return 1; case '2': return 2; @@ -184,6 +184,9 @@ namespace epee // convert two matching characters to int auto high = char_to_int(data++); + while (data != src.end() && !include(*data)) { + ++data; + } auto low = char_to_int(data++); result.push_back(high << 4 | low); diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp index 36a9ccdcc..6c9c52def 100644 --- a/tests/unit_tests/epee_utils.cpp +++ b/tests/unit_tests/epee_utils.cpp @@ -1221,6 +1221,9 @@ TEST(HexLocale, String) hex.assign("00:ff 0f:f0"); EXPECT_EQ(source, epee::from_hex_locale::to_vector(hex)); + hex.assign("0:0 f f 0:f f:0"); + EXPECT_EQ(source, epee::from_hex_locale::to_vector(hex)); + hex.append("f0"); EXPECT_EQ(source, epee::from_hex_locale::to_vector(boost::string_ref{hex.data(), hex.size() - 2})); }