diff --git a/common/string_utils.cpp b/common/string_utils.cpp index b7e994fc06..82d1da86e2 100644 --- a/common/string_utils.cpp +++ b/common/string_utils.cpp @@ -1675,16 +1675,13 @@ std::vector ExpandStackedPinNotation( const wxString& aPinName, bool* int CountStackedPinNotation( const wxString& aPinName, bool* aValid ) { + size_t len = aPinName.length(); + if( !aValid ) { // Fastest path when we're not interested in validity - size_t len = aPinName.length(); - if( len < 3 ) return 1; - - if( aPinName[0] != '[' || aPinName[len - 1] != ']' ) - return 1; } else { @@ -1696,7 +1693,7 @@ int CountStackedPinNotation( const wxString& aPinName, bool* aValid ) if( hasOpenBracket || hasCloseBracket ) { - if( aPinName[0] != '[' || aPinName[aPinName.length() - 1] != ']' ) + if( aPinName[0] != '[' || aPinName[len - 1] != ']' ) { *aValid = false; return 1; @@ -1704,6 +1701,9 @@ int CountStackedPinNotation( const wxString& aPinName, bool* aValid ) } } + if( aPinName[0] != '[' || aPinName[len - 1] != ']' ) + return 1; + const wxString inner = aPinName.Mid( 1, aPinName.Length() - 2 ); int count = 0;