@@ -8795,7 +8795,7 @@ static size_t getAlignOf(const ValueType& vt, const Settings& settings, ValueTyp
87958795 return 0 ;
87968796}
87978797
8798- size_t ValueType::getSizeOf ( const Settings& settings, Accuracy accuracy, SizeOf sizeOf, int maxRecursion) const
8798+ size_t ValueType::getSizeOf ( const Settings& settings, Accuracy accuracy, SizeOf sizeOf, int maxRecursion, bool * sizeOverflow ) const
87998799{
88008800 if (maxRecursion > settings.vfOptions .maxSizeOfRecursion ) {
88018801 // TODO: add bailout message
@@ -8832,10 +8832,15 @@ size_t ValueType::getSizeOf( const Settings& settings, Accuracy accuracy, SizeOf
88328832 bool overflow = false ;
88338833 auto accHelper = [&](size_t total, const ValueType& vt2, size_t dim, MathLib::bigint nBits) -> size_t {
88348834 const size_t charBit = settings.platform .char_bit ;
8835- size_t n = vt2.getSizeOf (settings, accuracy, SizeOf::Pointer, ++maxRecursion);
8835+ bool memberOverflow = false ;
8836+ size_t n = vt2.getSizeOf (settings, accuracy, SizeOf::Pointer, ++maxRecursion, &memberOverflow);
88368837 size_t a = getAlignOf (vt2, settings, accuracy, SizeOf::Pointer);
8837- if (n == 0 || a == 0 )
8838+ if (n == 0 || a == 0 ) {
8839+ // the member is a record whose own size does not fit, that is an overflow and not an unknown size
8840+ if (memberOverflow)
8841+ overflow = true ;
88388842 return accuracy == Accuracy::ExactOrZero ? 0 : total;
8843+ }
88398844 if (nBits >= 0 && n > maxSize / charBit) {
88408845 overflow = true ;
88418846 return accuracy == Accuracy::ExactOrZero ? 0 : total;
@@ -8908,8 +8913,9 @@ size_t ValueType::getSizeOf( const Settings& settings, Accuracy accuracy, SizeOf
89088913 return v;
89098914 });
89108915 }
8911- // the member sizes are not known exactly, the base class sizes must not be returned alone
8912- if (accuracy == Accuracy::ExactOrZero && (overflow || !result.success ))
8916+ if (overflow && sizeOverflow)
8917+ *sizeOverflow = true ;
8918+ if (accuracy == Accuracy::ExactOrZero && (overflow || (total == 0 && !result.success )))
89138919 return 0 ;
89148920 total = std::max (size_t {1 }, total);
89158921 size_t align = getAlignOf (*this , settings, accuracy, sizeOf);
0 commit comments