Use internal_strncpy to copy filename in linux procmaps
authorFrancis Ricci <francisjricci@gmail.com>
Tue, 11 Jul 2017 19:40:54 +0000 (19:40 +0000)
committerFrancis Ricci <francisjricci@gmail.com>
Tue, 11 Jul 2017 19:40:54 +0000 (19:40 +0000)
Cleaner than using a while loop to copy the string character by character.

Reviewers: alekseyshl, glider

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D35136

llvm-svn: 307696

compiler-rt/lib/sanitizer_common/sanitizer_procmaps_linux.cc

index 713bc21..1bcad2b 100644 (file)
@@ -62,13 +62,12 @@ bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) {
   while (current_ < next_line && *current_ == ' ')
     current_++;
   // Fill in the filename.
-  uptr i = 0;
-  while (current_ < next_line) {
-    if (segment->filename && i < segment->filename_size - 1)
-      segment->filename[i++] = *current_;
-    current_++;
+  if (segment->filename) {
+    uptr len = Min((uptr)(next_line - current_), segment->filename_size - 1);
+    internal_strncpy(segment->filename, current_, len);
+    segment->filename[len] = 0;
   }
-  if (segment->filename && i < segment->filename_size) segment->filename[i] = 0;
+
   current_ = next_line + 1;
   return true;
 }