Skip to content

Commit 3ec92cc

Browse files
author
Fytch
committed
make case_insensitive_eq robust to any kind of input; otherwise certain inputs can trigger an assertion or cause UB
1 parent ce2377c commit 3ec92cc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

include/ProgramOptions.hxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,12 @@ namespace po {
252252
// End of compatibility stuff
253253

254254
inline bool case_insensitive_eq(char x, char y) {
255-
PROGRAMOPTIONS_ASSERT(x >= 0 && y >= 0, "case_insensitive_eq: arguments must be representable as unsigned char");
256-
return x == y || std::tolower(x) == std::tolower(y);
255+
if(x == y)
256+
return true;
257+
if(x >= 0 && y >= 0)
258+
if(std::tolower(x) == std::tolower(y))
259+
return true;
260+
return false;
257261
}
258262

259263
inline std::size_t damerau_levenshtein(char const* a, char const* b, std::size_t i, std::size_t j, std::size_t cutoff = std::numeric_limits<std::size_t>::max(), std::size_t distance = 0) {

0 commit comments

Comments
 (0)