]> granicus.if.org Git - clang/commitdiff
Use LLVM's preferred current_path API instead of calling getcwd(3) directly.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 27 Apr 2013 08:12:29 +0000 (08:12 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 27 Apr 2013 08:12:29 +0000 (08:12 +0000)
The existing code also failed to allocate a buffer for it so getcwd corrupted
the stack. sys::fs::current_path takes care of the memory management.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180669 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp

index 40aebd4d1004ad0ba40f31e286613bef296fa18e..7e3ed2461aa9a9d8c32a3eebd4382f0f9c294d9a 100644 (file)
@@ -1775,9 +1775,6 @@ static bool shouldUseLeafFramePointer(const ArgList &Args,
   return true;
 }
 
-// FIXME: This is a temporary hack until I can find a fix that works for all
-// platforms.
-#define MAXPATHLEN 4096
 /// If the PWD environment variable is set, add a CC1 option to specify the
 /// debug compilation directory.
 static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs) {
@@ -1794,9 +1791,10 @@ static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs) {
     CmdArgs.push_back(Args.MakeArgString(pwd));
     return;
   }
+
   // Fall back to using getcwd.
-  char *cwd;
-  if (pwd && ::getcwd(cwd, MAXPATHLEN)) {
+  SmallString<128> cwd;
+  if (!llvm::sys::fs::current_path(cwd)) {
     CmdArgs.push_back("-fdebug-compilation-dir");
     CmdArgs.push_back(Args.MakeArgString(cwd));
   }