From 9e682362e978ee7e7afbb58dd1acd35226602074 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Tue, 14 Feb 2012 13:43:38 -0800 Subject: [PATCH] Fix bug in ArrayType::SizeUnsizedArrays(). If given an initializer list with too many elements for the actual array size, in some cases we would incorrectly resize the explicitly sized array to be the size implied by the initializer list. --- type.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/type.cpp b/type.cpp index f771dc73..01fb1c71 100644 --- a/type.cpp +++ b/type.cpp @@ -1431,8 +1431,10 @@ ArrayType::SizeUnsizedArrays(const Type *type, Expr *initExpr) { // If the current dimension is unsized, then size it according to the // length of the expression list - if (at->GetElementCount() == 0) + if (at->GetElementCount() == 0) { type = at->GetSizedArray(exprList->exprs.size()); + at = dynamic_cast(type); + } // Is there another nested level of expression lists? If not, bail out // now. Otherwise we'll use the first one to size the next dimension @@ -1443,8 +1445,7 @@ ArrayType::SizeUnsizedArrays(const Type *type, Expr *initExpr) { return type; const Type *nextType = at->GetElementType(); - const ArrayType *nextArrayType = - dynamic_cast(nextType); + const ArrayType *nextArrayType = dynamic_cast(nextType); if (nextArrayType != NULL && nextArrayType->GetElementCount() == 0) { // If the recursive call to SizeUnsizedArrays at the bottom of the // function is going to size an unsized dimension, make sure that @@ -1472,7 +1473,7 @@ ArrayType::SizeUnsizedArrays(const Type *type, Expr *initExpr) { // Recursively call SizeUnsizedArrays() to get the child type for the // array that we were able to size here. return new ArrayType(SizeUnsizedArrays(at->GetElementType(), nextList), - exprList->exprs.size()); + at->GetElementCount()); }