================
@@ -6673,12 +6673,28 @@ bool InterpretOffsetOf(InterpState &S, CodePtr OpPC, 
const OffsetOfExpr *E,
       // When generating bytecode, we put all the index expressions as Sint64 
on
       // the stack.
       int64_t Index = ArrayIndices[ArrayIndex];
+      if (Index < 0)
+        return Invalid(S, OpPC);
       const ArrayType *AT = S.getASTContext().getAsArrayType(CurrentType);
       if (!AT)
         return false;
       CurrentType = AT->getElementType();
       CharUnits ElementSize = 
S.getASTContext().getTypeSizeInChars(CurrentType);
-      Result += Index * ElementSize;
+      int64_t ElemSize = ElementSize.getQuantity();
+      if (Index != 0 && ElemSize > llvm::maxIntN(64) / Index) {
----------------
shafik wrote:

This need some parentheses, I get order of operations and all but really this 
is asking for a bug when someone and changes this and gets it wrong.

https://github.com/llvm/llvm-project/pull/204139
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to