Fix error checking in get_temp_file_name().

Checking errno without first checking that the call failed means that
if some other call prior to mkstemp failed with EINVAL prior to this,
the assert would fire even if mkstemp succeeded. If something failed
with EEXIST, it would go in to an infinite loop.

Change-Id: I3f140a3e15fe08664a38a8c9a950c4ed547eb481
llvm-svn: 229035
This commit is contained in:
Dan Albert 2015-02-13 03:02:28 +00:00
parent 63bef0d177
commit 0b15b14096
1 changed files with 7 additions and 4 deletions

View File

@ -69,10 +69,13 @@ get_temp_file_name()
std::string Name; std::string Name;
int FD = -1; int FD = -1;
do { do {
Name = "libcxx.XXXXXX"; Name = "libcxx.XXXXXX";
FD = mkstemp(&Name[0]); FD = mkstemp(&Name[0]);
assert(errno != EINVAL && "Something is wrong with the mkstemp's argument"); if (FD == -1 && errno == EINVAL) {
} while (FD == -1 || errno == EEXIST); perror("mkstemp");
abort();
}
} while (FD == -1);
close(FD); close(FD);
return Name; return Name;
#endif #endif