[clang] [clang][Sema] Avoid out-of-memory crash on huge designated initializer indices (PR #205503)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 30 17:52:27 PDT 2026
================
@@ -3375,6 +3377,32 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity,
DesignatedEndIndex.setIsUnsigned(true);
}
+ // The semantic form of an initializer list stores one pointer for every
+ // array element, including the elements omitted before a designator. Compute
+ // the required number of elements in a wider type so adding one cannot
+ // overflow.
+ llvm::APSInt NumInits = DesignatedEndIndex;
+ NumInits.setIsUnsigned(true);
+ NumInits = NumInits.extend(NumInits.getBitWidth() + 1);
+ ++NumInits;
+
+ // Keep a non-configurable ceiling so even an excessive command-line limit
+ // cannot request an initializer list too large for an unsigned-sized
+ // allocation.
----------------
erichkeane wrote:
We typically don't do this. IF a user sets this too high and we crash, so be it.
https://github.com/llvm/llvm-project/pull/205503
More information about the cfe-commits
mailing list