[PATCH] D139315: [NFC][LLVM-MT] Fix buffer-overflow when comparing buffers
Juan Manuel Martinez CaamaƱo via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 7 04:39:33 PST 2022
jmmartinez added inline comments.
================
Comment at: llvm/tools/llvm-mt/llvm-mt.cpp:153-157
+ bool SameSize =
+ OutputBuffer->getBufferSize() == FileBuffer->getBufferSize();
+ Same = SameSize && std::equal(OutputBuffer->getBufferStart(),
+ OutputBuffer->getBufferEnd(),
+ FileBuffer->getBufferStart());
----------------
jmmartinez wrote:
> abrachet wrote:
> > jmmartinez wrote:
> > > abrachet wrote:
> > > > That should work too. WDYT?
> > > I didn't know about that overload. I'll change it use your version.
> > Ah, sorry I didn't mean to keep SameSize in my suggested change. Just this should be sufficient
> > ```
> > Same = std::equal(OutputBuffer->getBufferStart(),
> > OutputBuffer->getBufferEnd(),
> > FileBuffer->getBufferStart());
> > FileBuffer->getBufferStart(),
> > FileBuffer->getBufferEnd());
> > ```
> I know, but checking the size first gives a shortcut in case the sizes are different (instead of scanning for a difference). Do you think we can keep it in this case ?
I just realized that with the right iterator type, std::equals computes the distance and does the shortcut on its own. I'm removing the size comparison.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139315/new/
https://reviews.llvm.org/D139315
More information about the llvm-commits
mailing list