[PATCH] D35136: Use internal_strncpy to copy filename in linux procmaps
Francis Ricci via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 9 06:14:16 PDT 2017
fjricci created this revision.
Herald added a subscriber: kubamracek.
Cleaner than using a while loop to copy the string character by character.
https://reviews.llvm.org/D35136
Files:
lib/sanitizer_common/sanitizer_procmaps_linux.cc
Index: lib/sanitizer_common/sanitizer_procmaps_linux.cc
===================================================================
--- lib/sanitizer_common/sanitizer_procmaps_linux.cc
+++ lib/sanitizer_common/sanitizer_procmaps_linux.cc
@@ -62,13 +62,12 @@
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35136.105669.patch
Type: text/x-patch
Size: 852 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170709/b09453bf/attachment-0001.bin>
More information about the llvm-commits
mailing list