Add a sanity check in SourceManager::getColumnNumber, make sure

we don't try to access beyond the buffer.

llvm-svn: 146305
This commit is contained in:
Argyrios Kyrtzidis 2011-12-10 00:30:38 +00:00
parent 88d510da9d
commit 6c8d29f7d1
1 changed files with 8 additions and 1 deletions

View File

@ -947,13 +947,20 @@ const char *SourceManager::getCharacterData(SourceLocation SL,
unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos,
bool *Invalid) const {
bool MyInvalid = false;
const char *Buf = getBuffer(FID, &MyInvalid)->getBufferStart();
const llvm::MemoryBuffer *MemBuf = getBuffer(FID, &MyInvalid);
if (Invalid)
*Invalid = MyInvalid;
if (MyInvalid)
return 1;
const char *Buf = MemBuf->getBufferStart();
if (Buf + FilePos >= MemBuf->getBufferEnd()) {
if (Invalid)
*Invalid = MyInvalid;
return 1;
}
unsigned LineStart = FilePos;
while (LineStart && Buf[LineStart-1] != '\n' && Buf[LineStart-1] != '\r')
--LineStart;