summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-09-10 14:05:21 (GMT)
committerBrad King <brad.king@kitware.com>2015-09-10 14:05:21 (GMT)
commit9c4a500f75e821ec6afb303a6ef5d951dcdc5c63 (patch)
treedc96bbd05a24c48b57ee1b0805648860546a511a
parent87a9061d57d2838b3793644a051542e329d305fa (diff)
downloadCMake-9c4a500f75e821ec6afb303a6ef5d951dcdc5c63.zip
CMake-9c4a500f75e821ec6afb303a6ef5d951dcdc5c63.tar.gz
CMake-9c4a500f75e821ec6afb303a6ef5d951dcdc5c63.tar.bz2
cmSystemTools: Fix TrimWhitespace for non-ascii strings (#15735)
Since commit v2.8.11~59^2 (cmSystemTools: Generalize TrimWhitespace to all whitespace, 2013-03-27) we incorrectly use `c <= ' '` to determine if `c` is a whitespace character. With a signed `char` type UTF-8 encoded strings may be truncated because values above 0x7f appear negative and therefore less than 0x20. Use `isspace(c)` instead.
-rw-r--r--Source/cmSystemTools.cxx4
1 files changed, 2 insertions, 2 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 84a288c..005a803 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -233,13 +233,13 @@ std::string cmSystemTools::HelpFileName(std::string name)
std::string cmSystemTools::TrimWhitespace(const std::string& s)
{
std::string::const_iterator start = s.begin();
- while(start != s.end() && *start <= ' ')
+ while (start != s.end() && cm_isspace(*start))
++start;
if (start == s.end())
return "";
std::string::const_iterator stop = s.end()-1;
- while(*stop <= ' ')
+ while (cm_isspace(*stop))
--stop;
return std::string(start, stop+1);
}