From 0b65b2dff64bdc6d71df94a13f89b7b1119b13b1 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 9 Aug 2018 01:24:52 +0200 Subject: Disallow packed encoding of arrays of structs. --- libsolidity/ast/Types.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 2dcfda42..5368e9c2 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -400,17 +400,17 @@ TypePointer Type::fullEncodingType(bool _inLibraryCall, bool _encoderV2, bool _p encodingType = encodingType->interfaceType(_inLibraryCall); if (encodingType) encodingType = encodingType->encodingType(); - if (auto structType = dynamic_cast(encodingType.get())) - { - // Structs are fine in the following circumstances: - // - ABIv2 without packed encoding or, - // - storage struct for a library - if (!( - (_encoderV2 && !_packed) || - (structType->location() == DataLocation::Storage && _inLibraryCall) - )) + // Structs are fine in the following circumstances: + // - ABIv2 without packed encoding or, + // - storage struct for a library + if (_inLibraryCall && encodingType->dataStoredIn(DataLocation::Storage)) + return encodingType; + TypePointer baseType = encodingType; + while (auto const* arrayType = dynamic_cast(baseType.get())) + baseType = arrayType->baseType(); + if (dynamic_cast(baseType.get())) + if (!_encoderV2 || _packed) return TypePointer(); - } return encodingType; } -- cgit