aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorPaul Pluzhnikov <ppluzhnikov@google.com>2022-10-18 20:47:55 +0000
committerDavid Blaikie <dblaikie@gmail.com>2022-10-18 20:48:00 +0000
commit5b773dcd2de0c4844814266a90dac14c349b8f18 (patch)
tree0a4a0c57ef48e5b9b96e13ce7b0501ccd8132904 /clang/lib/Basic/SourceManager.cpp
parent0e77b63bc01112594ec312b0d8892114ec263303 (diff)
downloadllvm-5b773dcd2de0c4844814266a90dac14c349b8f18.zip
llvm-5b773dcd2de0c4844814266a90dac14c349b8f18.tar.gz
llvm-5b773dcd2de0c4844814266a90dac14c349b8f18.tar.bz2
Fix incorrect check for running out of source locations.
When CurrentLoadedOffset is less than TotalSize, current code will trigger unsigned overflow and will not return an "allocation failed" indicator. Google ref: b/248613299 Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D135192
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r--clang/lib/Basic/SourceManager.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 6aae581..20bb594 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -454,8 +454,10 @@ SourceManager::AllocateLoadedSLocEntries(unsigned NumSLocEntries,
SourceLocation::UIntTy TotalSize) {
assert(ExternalSLocEntries && "Don't have an external sloc source");
// Make sure we're not about to run out of source locations.
- if (CurrentLoadedOffset - TotalSize < NextLocalOffset)
+ if (CurrentLoadedOffset < TotalSize ||
+ CurrentLoadedOffset - TotalSize < NextLocalOffset) {
return std::make_pair(0, 0);
+ }
LoadedSLocEntryTable.resize(LoadedSLocEntryTable.size() + NumSLocEntries);
SLocEntryLoaded.resize(LoadedSLocEntryTable.size());
CurrentLoadedOffset -= TotalSize;