diff options
author | Dylan Noblesmith <nobled@dreamwidth.org> | 2011-12-19 08:51:05 +0000 |
---|---|---|
committer | Dylan Noblesmith <nobled@dreamwidth.org> | 2011-12-19 08:51:05 +0000 |
commit | 098eaffc0c1784567ddccfe6f976ced6e904552e (patch) | |
tree | 6a44445209ca1c4b83124a0b318b424167a235bb /lib/Basic/SourceManager.cpp | |
parent | 2c2a385a1abef4d4b0b9f3712db3859da404b5eb (diff) | |
download | clang-098eaffc0c1784567ddccfe6f976ced6e904552e.tar.gz |
SourceManager: use getBufferSize()
Forming an out of bounds pointer to check if it's out
of bounds was undefined behavior.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146861 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/SourceManager.cpp')
-rw-r--r-- | lib/Basic/SourceManager.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 5221ed49aa..310b68eaeb 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -962,13 +962,13 @@ unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos, 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 @@ SourceLocation SourceManager::translateLineCol(FileID FID, 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); |