Author: hokein Date: Wed Aug 22 05:34:04 2018 New Revision: 340403 URL: http://llvm.org/viewvc/llvm-project?rev=340403&view=rev Log: [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 Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=340403&r1=340402&r2=340403&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original) +++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Wed Aug 22 05:34:04 2018 @@ -426,8 +426,8 @@ bool PrecompiledPreamble::CanReuse(const // 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. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits