diff --git a/SystemTools.cxx b/SystemTools.cxx
index 343acf28b15d5d6fb11d791057e55934e87362f7..7c48f39c2b32d407b7c7fe039c1d161da207e7ba 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -334,9 +334,9 @@ class SystemToolsTranslationMap :
 void SystemTools::GetPath(kwsys_stl::vector<kwsys_stl::string>& path, const char* env)
 {
 #if defined(_WIN32) && !defined(__CYGWIN__)
-  const char* pathSep = ";";
+  const char pathSep = ';';
 #else
-  const char* pathSep = ":";
+  const char pathSep = ':';
 #endif
   if(!env)
     {
@@ -351,7 +351,7 @@ void SystemTools::GetPath(kwsys_stl::vector<kwsys_stl::string>& path, const char
   kwsys_stl::string pathEnv = cpathEnv;
 
   // A hack to make the below algorithm work.
-  if(!pathEnv.empty() && pathEnv[pathEnv.length()-1] != pathSep[0])
+  if(!pathEnv.empty() && *pathEnv.rbegin() != pathSep)
     {
     pathEnv += pathSep;
     }