[cfe-commits] r72019 - /cfe/trunk/lib/Basic/SourceManager.cpp
Daniel Dunbar
daniel at zuster.org
Mon May 18 10:30:52 PDT 2009
Author: ddunbar
Date: Mon May 18 12:30:52 2009
New Revision: 72019
URL: http://llvm.org/viewvc/llvm-project?rev=72019&view=rev
Log:
Avoid potential out-of-bounds access in SourceManager::getLineNumber.
- Chris, please see added FIXMEs.
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=72019&r1=72018&r2=72019&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Mon May 18 12:30:52 2009
@@ -729,11 +729,22 @@
unsigned QueriedFilePos = FilePos+1;
+ // FIXME: I would like to be convinced that this code is worth being as
+ // complicated as it is, binary search isn't that slow.
+ //
+ // If it is worth being optimized, then in my opinion it could be more
+ // performant, simpler, and more obviously correct by just "galloping" outward
+ // from the queried file position. In fact, this could be incorporated into a
+ // generic algorithm such as lower_bound_with_hint.
+ //
+ // If someone gives me a test case where this matters, and I will do it! - DWD
+
// If the previous query was to the same file, we know both the file pos from
// that query and the line number returned. This allows us to narrow the
// search space from the entire file to something near the match.
if (LastLineNoFileIDQuery == FID) {
if (QueriedFilePos >= LastLineNoFilePos) {
+ // FIXME: Potential overflow?
SourceLineCache = SourceLineCache+LastLineNoResult-1;
// The query is likely to be nearby the previous one. Here we check to
@@ -753,7 +764,8 @@
}
}
} else {
- SourceLineCacheEnd = SourceLineCache+LastLineNoResult+1;
+ if (LastLineNoResult < Content->NumLines)
+ SourceLineCacheEnd = SourceLineCache+LastLineNoResult+1;
}
}
More information about the cfe-commits
mailing list