[llvm-commits] [llvm] r118105 - /llvm/trunk/lib/System/Unix/Path.inc
Dan Gohman
gohman at apple.com
Tue Nov 2 15:55:34 PDT 2010
Author: djg
Date: Tue Nov 2 17:55:34 2010
New Revision: 118105
URL: http://llvm.org/viewvc/llvm-project?rev=118105&view=rev
Log:
Avoid manipulating paths in fixed-sized arrays.
Modified:
llvm/trunk/lib/System/Unix/Path.inc
Modified: llvm/trunk/lib/System/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/Path.inc?rev=118105&r1=118104&r2=118105&view=diff
==============================================================================
--- llvm/trunk/lib/System/Unix/Path.inc (original)
+++ llvm/trunk/lib/System/Unix/Path.inc Tue Nov 2 17:55:34 2010
@@ -143,8 +143,7 @@
// Linux and FreeBSD have it. Others probably won't.
char pathname[] = "/tmp/llvm_XXXXXX";
if (0 == mkdtemp(pathname)) {
- MakeErrMsg(ErrMsg,
- std::string(pathname) + ": can't create temporary directory");
+ MakeErrMsg(ErrMsg, pathname + ": can't create temporary directory");
return Path();
}
Path result;
@@ -681,8 +680,7 @@
bool
Path::createDirectoryOnDisk( bool create_parents, std::string* ErrMsg ) {
// Get a writeable copy of the path name
- char pathname[MAXPATHLEN];
- path.copy(pathname,MAXPATHLEN);
+ std::string pathname(path);
// Null-terminate the last component
size_t lastchar = path.length() - 1 ;
@@ -692,7 +690,7 @@
pathname[lastchar] = '\0';
- if (createDirectoryHelper(pathname, pathname+lastchar, create_parents))
+ if (createDirectoryHelper(&pathname[0], &pathname[lastchar], create_parents))
return MakeErrMsg(ErrMsg,
std::string(pathname) + ": can't create directory");
@@ -759,17 +757,15 @@
}
// Otherwise, try to just remove the one directory.
- char pathname[MAXPATHLEN];
- path.copy(pathname, MAXPATHLEN);
+ std::string pathname(path);
size_t lastchar = path.length() - 1;
if (pathname[lastchar] == '/')
pathname[lastchar] = '\0';
else
pathname[lastchar+1] = '\0';
- if (rmdir(pathname) != 0)
- return MakeErrMsg(ErrStr,
- std::string(pathname) + ": can't erase directory");
+ if (rmdir(pathname.c_str()) != 0)
+ return MakeErrMsg(ErrStr, pathname + ": can't erase directory");
return false;
}
More information about the llvm-commits
mailing list