[cfe-commits] r146861 - /cfe/trunk/lib/Basic/SourceManager.cpp
Dylan Noblesmith
nobled at dreamwidth.org
Mon Dec 19 00:51:05 PST 2011
Author: nobled
Date: Mon Dec 19 02:51:05 2011
New Revision: 146861
URL: http://llvm.org/viewvc/llvm-project?rev=146861&view=rev
Log:
SourceManager: use getBufferSize()
Forming an out of bounds pointer to check if it's out
of bounds was undefined behavior.
Modified:
cfe/trunk/lib/Basic/SourceManager.cpp
Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=146861&r1=146860&r2=146861&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Mon Dec 19 02:51:05 2011
@@ -962,13 +962,13 @@
if (MyInvalid)
return 1;
- const char *Buf = MemBuf->getBufferStart();
- if (Buf + FilePos >= MemBuf->getBufferEnd()) {
+ if (FilePos >= MemBuf->getBufferSize()) {
if (Invalid)
*Invalid = MyInvalid;
return 1;
}
+ const char *Buf = MemBuf->getBufferStart();
unsigned LineStart = FilePos;
while (LineStart && Buf[LineStart-1] != '\n' && Buf[LineStart-1] != '\r')
--LineStart;
@@ -1524,9 +1524,10 @@
return FileLoc.getLocWithOffset(Size);
}
+ const llvm::MemoryBuffer *Buffer = Content->getBuffer(Diag, *this);
unsigned FilePos = Content->SourceLineCache[Line - 1];
- const char *Buf = Content->getBuffer(Diag, *this)->getBufferStart() + FilePos;
- unsigned BufLength = Content->getBuffer(Diag, *this)->getBufferEnd() - Buf;
+ const char *Buf = Buffer->getBufferStart() + FilePos;
+ unsigned BufLength = Buffer->getBufferSize() - FilePos;
if (BufLength == 0)
return FileLoc.getLocWithOffset(FilePos);
More information about the cfe-commits
mailing list