r195024 - Adding an assert to help catch possible buffer underruns.

Aaron Ballman aaron at aaronballman.com
Mon Nov 18 10:29:00 PST 2013


Author: aaronballman
Date: Mon Nov 18 12:29:00 2013
New Revision: 195024

URL: http://llvm.org/viewvc/llvm-project?rev=195024&view=rev
Log:
Adding an assert to help catch possible buffer underruns.

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=195024&r1=195023&r2=195024&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Mon Nov 18 12:29:00 2013
@@ -1757,6 +1757,10 @@ FileID SourceManager::translateFile(cons
 SourceLocation SourceManager::translateLineCol(FileID FID,
                                                unsigned Line,
                                                unsigned Col) const {
+  // Lines are used as a one-based index into a zero-based array. This assert
+  // checks for possible buffer underruns.
+  assert(Line != 0 && "Passed a zero-based line");
+
   if (FID.isInvalid())
     return SourceLocation();
 





More information about the cfe-commits mailing list