From 00ed9870d98b93d8a6438e5cf9058ebbe10dab01 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 13 Feb 2015 03:02:28 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@229035 91177308-0d34-0410-b5e6-96231b3b80d8 Change-Id: I512f29f2cb4b379e9f33e9bc12c060851152647c --- test/support/platform_support.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/support/platform_support.h b/test/support/platform_support.h index d8b6be623..180765ec5 100644 --- a/test/support/platform_support.h +++ b/test/support/platform_support.h @@ -69,10 +69,13 @@ get_temp_file_name() std::string Name; int FD = -1; do { - Name = "libcxx.XXXXXX"; - FD = mkstemp(&Name[0]); - assert(errno != EINVAL && "Something is wrong with the mkstemp's argument"); - } while (FD == -1 || errno == EEXIST); + Name = "libcxx.XXXXXX"; + FD = mkstemp(&Name[0]); + if (FD == -1 && errno == EINVAL) { + perror("mkstemp"); + abort(); + } + } while (FD == -1); close(FD); return Name; #endif