forked from OSchip/llvm-project
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:
parent
88d510da9d
commit
6c8d29f7d1
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue