llvm.org GIT mirror llvm / ef5120c
[Path] Set FD to -1 in moved-from TempFile When moving a temp file, explicitly set the file descriptor to -1 so we can never accidentally close the moved-from TempFile. Differential revision: https://reviews.llvm.org/D63087 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363083 91177308-0d34-0410-b5e6-96231b3b80d8 Jonas Devlieghere a month ago
2 changed file(s) with 3 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
11241124 TmpName = std::move(Other.TmpName);
11251125 FD = Other.FD;
11261126 Other.Done = true;
1127 Other.FD = -1;
11271128 return *this;
11281129 }
11291130
577577 auto TempFileOrError = fs::TempFile::create(TestDirectory + "/test-%%%%");
578578 ASSERT_TRUE((bool)TempFileOrError);
579579 fs::TempFile File = std::move(*TempFileOrError);
580 ASSERT_EQ(-1, TempFileOrError->FD);
580581 ASSERT_FALSE((bool)File.keep(TestDirectory + "/keep"));
581582 ASSERT_FALSE((bool)File.discard());
582583 ASSERT_TRUE(fs::exists(TestDirectory + "/keep"));
588589 auto TempFileOrError = fs::TempFile::create(TestDirectory + "/test-%%%%");
589590 ASSERT_TRUE((bool)TempFileOrError);
590591 fs::TempFile File = std::move(*TempFileOrError);
592 ASSERT_EQ(-1, TempFileOrError->FD);
591593 ASSERT_FALSE((bool)File.discard());
592594 ASSERT_FALSE((bool)File.discard());
593595 ASSERT_FALSE(fs::exists(TestDirectory + "/keep"));