]> granicus.if.org Git - clang/commitdiff
[Preamble] Fix an undefined behavior when checking an empty preamble can be reused.
authorHaojian Wu <hokein@google.com>
Wed, 22 Aug 2018 12:34:04 +0000 (12:34 +0000)
committerHaojian Wu <hokein@google.com>
Wed, 22 Aug 2018 12:34:04 +0000 (12:34 +0000)
Summary: Passing nullptr to memcmp is UB.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340403 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/PrecompiledPreamble.cpp

index 4bff339711d0405493316ca90c68ce677db4bb81..239e0dd974aa9b5cd61f211f6a19804c710ccb1d 100644 (file)
@@ -426,8 +426,8 @@ bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation,
   // new main file.
   if (PreambleBytes.size() != Bounds.Size ||
       PreambleEndsAtStartOfLine != Bounds.PreambleEndsAtStartOfLine ||
-      memcmp(PreambleBytes.data(), MainFileBuffer->getBufferStart(),
-             Bounds.Size) != 0)
+      !std::equal(PreambleBytes.begin(), PreambleBytes.end(),
+                  MainFileBuffer->getBuffer().begin()))
     return false;
   // The preamble has not changed. We may be able to re-use the precompiled
   // preamble.