diff --git a/Glob.cxx b/Glob.cxx index e2af4ec36f..90970ea589 100644 --- a/Glob.cxx +++ b/Glob.cxx @@ -162,7 +162,7 @@ std::string Glob::PatternToRegex(std::string const& pattern, // On case-insensitive systems file names are converted to lower // case before matching. if (!preserve_case) { - ch = tolower(ch); + ch = tolower(static_cast(ch)); } } #endif diff --git a/ProcessUNIX.c b/ProcessUNIX.c index a918b8d9a7..01dc039822 100644 --- a/ProcessUNIX.c +++ b/ProcessUNIX.c @@ -2502,7 +2502,8 @@ static pid_t kwsysProcessFork(kwsysProcess* cp, corresponding parsing format string. The parsing format should have two integers to store: the pid and then the ppid. */ #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ - defined(__OpenBSD__) || defined(__GLIBC__) || defined(__GNU__) + defined(__NetBSD__) || defined(__OpenBSD__) || defined(__GLIBC__) || \ + defined(__GNU__) # define KWSYSPE_PS_COMMAND "ps axo pid,ppid" # define KWSYSPE_PS_FORMAT "%d %d\n" #elif defined(__sun) && (defined(__SVR4) || defined(__svr4__)) /* Solaris */ diff --git a/SystemTools.cxx b/SystemTools.cxx index f8205c795d..3f036df651 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -320,7 +320,8 @@ inline char const* Getcwd(char* buf, unsigned int len) if (nlen < len) { // make sure the drive letter is capital if (nlen > 1 && buf[1] == ':') { - buf[0] = toupper(buf[0]); + buf[0] = + static_cast(toupper(static_cast(buf[0]))); } return buf; } @@ -552,7 +553,8 @@ std::string SystemToolsStatic::GetCasePathName(std::string const& pathIn) casePath = path_components[idx++]; // make sure drive letter is always upper case if (casePath.size() > 1 && casePath[1] == ':') { - casePath[0] = toupper(casePath[0]); + casePath[0] = static_cast( + toupper(static_cast(casePath[0]))); } char const* sep = ""; @@ -1656,9 +1658,11 @@ std::string SystemTools::Capitalized(std::string const& s) return n; } n.resize(s.size()); - n[0] = static_cast(toupper(s[0])); + n[0] = static_cast( + toupper(static_cast(s[0]))); for (size_t i = 1; i < s.size(); i++) { - n[i] = static_cast(tolower(s[i])); + n[i] = static_cast( + tolower(static_cast(s[i]))); } return n; } @@ -1677,7 +1681,8 @@ std::string SystemTools::CapitalizedWords(std::string const& s) if (isalpha(s[i]) && (i == 0 || isspace(s[i - 1]))) #endif { - n[i] = static_cast(toupper(s[i])); + n[i] = static_cast( + toupper(static_cast(s[i]))); } } return n; @@ -1697,7 +1702,8 @@ std::string SystemTools::UnCapitalizedWords(std::string const& s) if (isalpha(s[i]) && (i == 0 || isspace(s[i - 1]))) #endif { - n[i] = static_cast(tolower(s[i])); + n[i] = static_cast( + tolower(static_cast(s[i]))); } } return n; @@ -1768,7 +1774,8 @@ std::string SystemTools::LowerCase(std::string const& s) std::string n; n.resize(s.size()); for (size_t i = 0; i < s.size(); i++) { - n[i] = static_cast(tolower(s[i])); + n[i] = static_cast( + tolower(static_cast(s[i]))); } return n; } @@ -1779,7 +1786,8 @@ std::string SystemTools::UpperCase(std::string const& s) std::string n; n.resize(s.size()); for (size_t i = 0; i < s.size(); i++) { - n[i] = static_cast(toupper(s[i])); + n[i] = static_cast( + toupper(static_cast(s[i]))); } return n; } @@ -2743,8 +2751,8 @@ int SystemTools::Strucmp(char const* l, char const* r) int lc; int rc; do { - lc = tolower(*l++); - rc = tolower(*r++); + lc = tolower(static_cast(*l++)); + rc = tolower(static_cast(*r++)); } while (lc == rc && lc); return lc - rc; } diff --git a/testSystemTools.cxx b/testSystemTools.cxx index dff9dd6224..b94b8f6f1b 100644 --- a/testSystemTools.cxx +++ b/testSystemTools.cxx @@ -534,6 +534,21 @@ static bool CheckStringOperations() { bool res = true; + // Case conversion should only affect ASCII bytes. + // Test using a UTF-8 Copyright Symbol because its leading byte + // is transformed by MSVC's tolower in a US-ASCII locale. + static std::string const sampleUTF8 = "y\xC2\xA9Z"; // Copyright Symbol + if (kwsys::SystemTools::LowerCase(sampleUTF8) != "y\xC2\xA9z") { + std::cerr << "Problem with LowerCase " << '"' << sampleUTF8 << '"' + << std::endl; + res = false; + } + if (kwsys::SystemTools::UpperCase(sampleUTF8) != "Y\xC2\xA9Z") { + std::cerr << "Problem with UpperCase " << '"' << sampleUTF8 << '"' + << std::endl; + res = false; + } + std::string test = "mary had a little lamb."; if (kwsys::SystemTools::CapitalizedWords(test) != "Mary Had A Little Lamb.") {