From 1ef6ff504a28efb644792946093a9dd1fb963ee4 Mon Sep 17 00:00:00 2001
From: Andy Cedilnik <andy.cedilnik@kitware.com>
Date: Wed, 21 Apr 2004 10:33:07 -0400
Subject: [PATCH] BUG: Prevent crash when the current working directory cannot
 be established

---
 SystemTools.cxx | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/SystemTools.cxx b/SystemTools.cxx
index e4fa0652..e041f06a 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -1281,7 +1281,12 @@ int SystemTools::ChangeDirectory(const char *dir)
 kwsys_stl::string SystemTools::GetCurrentWorkingDirectory()
 {
   char buf[2048];
-  kwsys_stl::string path = Getcwd(buf, 2048);
+  const char* cwd = Getcwd(buf, 2048);
+  kwsys_stl::string path;
+  if ( cwd )
+    {
+    path = cwd;
+    }
   return path;
 }
 
-- 
GitLab