[PATCH] D48250: [sanitizer_common] Use O_TRUNC for WrOnly access mode.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 15 20:12:30 PDT 2018


MaskRay updated this revision to Diff 151601.
MaskRay added a comment.

Remove change to solaris which seems already broken.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D48250

Files:
  lib/sanitizer_common/sanitizer_posix.cc
  lib/sanitizer_common/sanitizer_rtems.cc
  lib/sanitizer_common/tests/sanitizer_libc_test.cc


Index: lib/sanitizer_common/tests/sanitizer_libc_test.cc
===================================================================
--- lib/sanitizer_common/tests/sanitizer_libc_test.cc
+++ lib/sanitizer_common/tests/sanitizer_libc_test.cc
@@ -108,6 +108,12 @@
   temp_file_name(tmpfile, sizeof(tmpfile), "sanitizer_common.fileops.tmp.");
   fd_t fd = OpenFile(tmpfile, WrOnly);
   ASSERT_NE(fd, kInvalidFd);
+  ASSERT_FALSE(internal_iserror(internal_write(fd, "A", 1)));
+  CloseFile(fd);
+
+  fd = OpenFile(tmpfile, WrOnly);
+  ASSERT_NE(fd, kInvalidFd);
+  EXPECT_EQ(internal_lseek(fd, 0, SEEK_END), 0u);
   uptr bytes_written = 0;
   EXPECT_TRUE(WriteToFile(fd, str1, len1, &bytes_written));
   EXPECT_EQ(len1, bytes_written);
Index: lib/sanitizer_common/sanitizer_rtems.cc
===================================================================
--- lib/sanitizer_common/sanitizer_rtems.cc
+++ lib/sanitizer_common/sanitizer_rtems.cc
@@ -193,7 +193,7 @@
   int flags;
   switch (mode) {
     case RdOnly: flags = O_RDONLY; break;
-    case WrOnly: flags = O_WRONLY | O_CREAT; break;
+    case WrOnly: flags = O_WRONLY | O_CREAT | O_TRUNC; break;
     case RdWr: flags = O_RDWR | O_CREAT; break;
   }
   fd_t res = open(filename, flags, 0660);
Index: lib/sanitizer_common/sanitizer_posix.cc
===================================================================
--- lib/sanitizer_common/sanitizer_posix.cc
+++ lib/sanitizer_common/sanitizer_posix.cc
@@ -160,7 +160,7 @@
   int flags;
   switch (mode) {
     case RdOnly: flags = O_RDONLY; break;
-    case WrOnly: flags = O_WRONLY | O_CREAT; break;
+    case WrOnly: flags = O_WRONLY | O_CREAT | O_TRUNC; break;
     case RdWr: flags = O_RDWR | O_CREAT; break;
   }
   fd_t res = internal_open(filename, flags, 0660);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48250.151601.patch
Type: text/x-patch
Size: 1757 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180616/f0a80f50/attachment.bin>


More information about the llvm-commits mailing list