[clang] 5b773dc - Fix incorrect check for running out of source locations.
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 18 13:48:10 PDT 2022
Author: Paul Pluzhnikov
Date: 2022-10-18T20:48:00Z
New Revision: 5b773dcd2de0c4844814266a90dac14c349b8f18
URL: https://github.com/llvm/llvm-project/commit/5b773dcd2de0c4844814266a90dac14c349b8f18
DIFF: https://github.com/llvm/llvm-project/commit/5b773dcd2de0c4844814266a90dac14c349b8f18.diff
LOG: 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
Added:
Modified:
clang/lib/Basic/SourceManager.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 6aae581be8001..20bb594106713 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;
More information about the cfe-commits
mailing list