Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Unified Diff: third_party/android_crazy_linker/src/src/crazy_linker_line_reader.cpp

Issue 405153002: Provide consistent behaviour for memchr(_,_,0) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/android_crazy_linker/src/src/crazy_linker_line_reader.cpp
diff --git a/third_party/android_crazy_linker/src/src/crazy_linker_line_reader.cpp b/third_party/android_crazy_linker/src/src/crazy_linker_line_reader.cpp
index c020daad1c99ed6d6ed4b81fcc548ec096a258c5..8c6337017ba19bdc4fbd0710931a29eb5bf1e94b 100644
--- a/third_party/android_crazy_linker/src/src/crazy_linker_line_reader.cpp
+++ b/third_party/android_crazy_linker/src/src/crazy_linker_line_reader.cpp
@@ -51,10 +51,15 @@ bool LineReader::GetNextLine() {
buff_size_,
buff_capacity_);
- // Find the end of the current line in the current buffer.
+ // Find the end of the current line in the current buffer. The result
+ // of memchr(_,_,0) is undefined, treated as not-found.
const char* line = buff_ + line_start_;
- const char* line_end = reinterpret_cast<const char*>(
- ::memchr(line, '\n', buff_size_ - line_start_));
+ const size_t range = buff_size_ - line_start_;
+ const char* line_end;
+ if (range > 0)
+ line_end = reinterpret_cast<const char*>(::memchr(line, '\n', range));
+ else
+ line_end = NULL;
if (line_end != NULL) {
// Found one, return it directly.
line_len_ = static_cast<size_t>(line_end + 1 - line);

Powered by Google App Engine
This is Rietveld 408576698