Browse Source

BUG: fix #8704, sometimes crash if include_directories() is called with a whitespace string

Alex
Alexander Neundorf 16 years ago
parent
commit
3fe6b3ce37
1 changed files with 7 additions and 12 deletions
  1. 7 12
      Source/cmIncludeDirectoryCommand.cxx

+ 7 - 12
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);