diff --git a/src/utils/StringUtils.h b/src/utils/StringUtils.h index 78721f112..cc1cf4cd4 100644 --- a/src/utils/StringUtils.h +++ b/src/utils/StringUtils.h @@ -106,7 +106,7 @@ inline std::string LeftTrim(std::string str, char c) // Starting from the left, trim all the space characters i.e. space, tabulation, etc. inline std::string LeftTrim(std::string str) { - const auto it = std::find_if(str.begin(), str.end(), [](char ch) { return !std::isspace(ch); }); + const auto it = std::find_if(str.begin(), str.end(), [](char ch) { return !std::isspace(static_cast(ch)); }); str.erase(str.begin(), it); return str; } @@ -123,7 +123,7 @@ inline std::string RightTrim(std::string str, char c) inline std::string RightTrim(std::string str) { const auto it = - std::find_if(str.rbegin(), str.rend(), [](char ch) { return !std::isspace(ch); }); + std::find_if(str.rbegin(), str.rend(), [](char ch) { return !std::isspace(static_cast(ch)); }); str.erase(it.base(), str.end()); return str; } diff --git a/tests/utils/StringUtils_tests.cpp b/tests/utils/StringUtils_tests.cpp index fb9cb79de..0154a4fc1 100644 --- a/tests/utils/StringUtils_tests.cpp +++ b/tests/utils/StringUtils_tests.cpp @@ -50,6 +50,12 @@ OCIO_ADD_TEST(StringUtils, trim) const std::string str = StringUtils::Trim(ref); OCIO_CHECK_EQUAL(str, "lOwEr 1*& ctfG"); } + + { + // Test that no assert happens when the Trim argument is not an unsigned char (see issue #1874). + constexpr char ref2[]{ -1, -2, -3, '\0' }; + const std::string str = StringUtils::Trim(ref2); + } } OCIO_ADD_TEST(StringUtils, split)