Skip to content

Commit

Permalink
Merge pull request #18485 from dan131riley/TFileService_getcwd
Browse files Browse the repository at this point in the history
fix getcwd() usage to avoid undefined behavior
  • Loading branch information
davidlange6 committed Apr 29, 2017
2 parents 178cbb4 + 8ff1714 commit 446cd60
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions CommonTools/UtilAlgos/src/TFileService.cc
Expand Up @@ -88,9 +88,18 @@ void TFileService::afterBeginJob() {

if(!fileName_.empty()) {
if(!fileNameRecorded_) {
std::string fullName;
fullName.reserve(1024);
fullName = getcwd(&fullName[0],1024);
std::string fullName(1024, '\0');

while (getcwd(&fullName[0], fullName.size()) == nullptr) {
if (errno != ERANGE) {
throw cms::Exception("TFileService")
<< "Failed to get current directory (errno=" << errno
<< "): " << strerror(errno);
}
fullName.resize(fullName.size()*2, '\0');
}
fullName.resize(fullName.find('\0'));

fullName += "/" + fileName_;

std::map<std::string, std::string> fileData;
Expand Down

0 comments on commit 446cd60

Please sign in to comment.