From 3fe6b3ce370ea8916987b4115ca7c0bf72f831b9 Mon Sep 17 00:00:00 2001 From: Alexander Neundorf Date: Thu, 12 Mar 2009 19:24:27 -0400 Subject: BUG: fix #8704, sometimes crash if include_directories() is called with a whitespace string Alex --- Source/cmIncludeDirectoryCommand.cxx | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx index 1c8bcc1..8404bc8 100644 --- a/Source/cmIncludeDirectoryCommand.cxx +++ b/Source/cmIncludeDirectoryCommand.cxx @@ -94,22 +94,17 @@ void cmIncludeDirectoryCommand::AddDirectory(const char *i, } // remove any leading or trailing spaces and \r - pos = ret.size()-1; - while(ret[pos] == ' ' || ret[pos] == '\r') + std::string::size_type b = ret.find_first_not_of(" \r"); + std::string::size_type e = ret.find_last_not_of(" \r"); + if ((b!=ret.npos) && (e!=ret.npos)) { - ret.erase(pos); - pos--; + ret.assign(ret, b, 1+e-b); // copy the remaining substring } - pos = 0; - while(ret.size() && ret[pos] == ' ' || ret[pos] == '\r') + else { - ret.erase(pos,1); + return; // if we get here, we had only whitespace in the string } - if (!ret.size()) - { - return; - } - + if (!cmSystemTools::IsOff(ret.c_str())) { cmSystemTools::ConvertToUnixSlashes(ret); -- cgit v0.12