[PATCH] D135192: Fix incorrect check for running out of source locations.

Paul Pluzhnikov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 4 14:11:53 PDT 2022


ppluzhnikov created this revision.
Herald added a project: All.
ppluzhnikov published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When CurrentLoadedOffset is less than TotalSize, current code will
trigger unsigned overflow and will not return an "allocation failed"
indicator.

Google ref: b/248613299


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135192

Files:
  clang/lib/Basic/SourceManager.cpp


Index: clang/lib/Basic/SourceManager.cpp
===================================================================
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -455,8 +455,10 @@
                                          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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135192.465135.patch
Type: text/x-patch
Size: 790 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221004/ec8223a6/attachment.bin>


More information about the cfe-commits mailing list