From: Haojian Wu Date: Wed, 22 Aug 2018 12:34:04 +0000 (+0000) Subject: [Preamble] Fix an undefined behavior when checking an empty preamble can be reused. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e012984b099032dd8a65151a7882c305e1f37b4;p=clang [Preamble] Fix an undefined behavior when checking an empty preamble can be reused. 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 --- diff --git a/lib/Frontend/PrecompiledPreamble.cpp b/lib/Frontend/PrecompiledPreamble.cpp index 4bff339711..239e0dd974 100644 --- a/lib/Frontend/PrecompiledPreamble.cpp +++ b/lib/Frontend/PrecompiledPreamble.cpp @@ -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.