From e8b9cd64fc555b74d9e550f515b2b584e037340d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Fri, 23 Sep 2022 20:19:56 +0200 Subject: [PATCH] refs #10663 - only match start pattern in `Library::detectContainerInternal()` if necessary (#4499) --- lib/library.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/library.cpp b/lib/library.cpp index ed902c9fe..62b26e006 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -1141,30 +1141,33 @@ const Library::Container* Library::detectContainerInternal(const Token* typeStar if (container.startPattern.empty()) continue; - if (!Token::Match(typeStart, container.startPattern2.c_str())) - continue; - // If endPattern is undefined, it will always match, but itEndPattern has to be defined. if (detect != IteratorOnly && container.endPattern.empty()) { + if (!Token::Match(typeStart, container.startPattern2.c_str())) + continue; + if (isIterator) *isIterator = false; return &container; } for (const Token* tok = typeStart; tok && !tok->varId(); tok = tok->next()) { - if (tok->link()) { - if (detect != ContainerOnly && Token::Match(tok->link(), container.itEndPattern.c_str())) { - if (isIterator) - *isIterator = true; - return &container; - } - if (detect != IteratorOnly && Token::Match(tok->link(), container.endPattern.c_str())) { - if (isIterator) - *isIterator = false; - return &container; - } - break; + if (!tok->link()) + continue; + + const bool matchedStartPattern = Token::Match(typeStart, container.startPattern2.c_str()); + + if (detect != ContainerOnly && matchedStartPattern && Token::Match(tok->link(), container.itEndPattern.c_str())) { + if (isIterator) + *isIterator = true; + return &container; } + if (detect != IteratorOnly && matchedStartPattern && Token::Match(tok->link(), container.endPattern.c_str())) { + if (isIterator) + *isIterator = false; + return &container; + } + break; } } return nullptr;