From 4ba9af11417c45abc063c9906c7e593b85fccc17 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 20 Apr 2015 13:04:30 +0000 Subject: Don't allow pwrite to resize a stream. The current implementations could exhibit some behavior differences: raw_fd_ostream: Whatever the underlying fd does with seek+write. In a normal file, the write position would be back to the old offset. raw_svector_ostream: The write position is always the end of the stream, so after pwrite the write position would be the new end. This matches what OS_X (all BSD?) do with a pwrite in a O_APPEND fd. Given that we don't need that feature and don't use O_APPEND a lot in LLVM, just disallow it. I am open to suggestions on renaming pwrite to something else, but this fixes the issue for now. Thanks to Yaron Keren for reporting it. llvm-svn: 235303 --- llvm/unittests/Support/raw_pwrite_stream_test.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'llvm/unittests/Support/raw_pwrite_stream_test.cpp') diff --git a/llvm/unittests/Support/raw_pwrite_stream_test.cpp b/llvm/unittests/Support/raw_pwrite_stream_test.cpp index bcbb29b86bd..2792f44b605 100644 --- a/llvm/unittests/Support/raw_pwrite_stream_test.cpp +++ b/llvm/unittests/Support/raw_pwrite_stream_test.cpp @@ -16,10 +16,18 @@ using namespace llvm; namespace { TEST(raw_pwrite_ostreamTest, TestSVector) { - SmallString<64> Buffer; + SmallVector Buffer; raw_svector_ostream OS(Buffer); + OS << "abcd"; StringRef Test = "test"; OS.pwrite(Test.data(), Test.size(), 0); EXPECT_EQ(Test, OS.str()); + +#ifdef GTEST_HAS_DEATH_TEST +#ifndef NDEBUG + EXPECT_DEATH(OS.pwrite("12345", 5, 0), + "We don't support extending the stream"); +#endif +#endif } } -- cgit v1.2.3