[compiler-rt] r231502 - [asan] Fix 2 problems in nohugepage_test.

Kostya Serebryany kcc at google.com
Fri Mar 6 11:33:58 PST 2015


Author: kcc
Date: Fri Mar  6 13:33:58 2015
New Revision: 231502

URL: http://llvm.org/viewvc/llvm-project?rev=231502&view=rev
Log:
[asan] Fix 2 problems in nohugepage_test.

1. /proc/self/smaps may be bigger than 1 << 14.  On my machine, it is
26KB.
2. The read system call may return a partially filled buffer.  We need
to check the return value from read.

Patch by H.J. Lu

Modified:
    compiler-rt/trunk/test/asan/TestCases/Linux/nohugepage_test.cc

Modified: compiler-rt/trunk/test/asan/TestCases/Linux/nohugepage_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/nohugepage_test.cc?rev=231502&r1=231501&r2=231502&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/nohugepage_test.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/nohugepage_test.cc Fri Mar  6 13:33:58 2015
@@ -22,15 +22,31 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <errno.h>
 #include <sanitizer/asan_interface.h>
 
-char FileContents[1 << 14];
+char FileContents[1 << 16];
 
 void FileToString(const char *path) {
   FileContents[0] = 0;
   int fd = open(path, 0);
   if (fd < 0) return;
-  ssize_t res = read(fd, FileContents, sizeof(FileContents) - 1);
+  char *p = FileContents;
+  ssize_t size = sizeof(FileContents) - 1;
+  ssize_t res = 0;
+  do {
+    ssize_t got = read (fd, p, size);
+    if (got == 0)
+      break;
+    else if (got > 0)
+      {
+        p += got;
+        res += got;
+        size -= got;
+      }
+    else if (errno != EINTR)
+      break;
+  } while (size > 0 && res < sizeof(FileContents));
   if (res >= 0)
     FileContents[res] = 0;
 }





More information about the llvm-commits mailing list