[cfe-commits] r146305 - /cfe/trunk/lib/Basic/SourceManager.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Dec 9 16:30:38 PST 2011


Author: akirtzidis
Date: Fri Dec  9 18:30:38 2011
New Revision: 146305

URL: http://llvm.org/viewvc/llvm-project?rev=146305&view=rev
Log:
Add a sanity check in SourceManager::getColumnNumber, make sure
we don't try to access beyond the buffer.

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=146305&r1=146304&r2=146305&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Fri Dec  9 18:30:38 2011
@@ -947,13 +947,20 @@
 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;





More information about the cfe-commits mailing list