refs #10663 - only match start pattern in `Library::detectContainerInternal()` if necessary (#4499)

This commit is contained in:
Oliver Stöneberg 2022-09-23 20:19:56 +02:00 committed by GitHub
parent d608bec414
commit e8b9cd64fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 15 deletions

View File

@ -1141,24 +1141,28 @@ const Library::Container* Library::detectContainerInternal(const Token* typeStar
if (container.startPattern.empty()) if (container.startPattern.empty())
continue; 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())) if (!Token::Match(typeStart, container.startPattern2.c_str()))
continue; continue;
// If endPattern is undefined, it will always match, but itEndPattern has to be defined.
if (detect != IteratorOnly && container.endPattern.empty()) {
if (isIterator) if (isIterator)
*isIterator = false; *isIterator = false;
return &container; return &container;
} }
for (const Token* tok = typeStart; tok && !tok->varId(); tok = tok->next()) { for (const Token* tok = typeStart; tok && !tok->varId(); tok = tok->next()) {
if (tok->link()) { if (!tok->link())
if (detect != ContainerOnly && Token::Match(tok->link(), container.itEndPattern.c_str())) { 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) if (isIterator)
*isIterator = true; *isIterator = true;
return &container; return &container;
} }
if (detect != IteratorOnly && Token::Match(tok->link(), container.endPattern.c_str())) { if (detect != IteratorOnly && matchedStartPattern && Token::Match(tok->link(), container.endPattern.c_str())) {
if (isIterator) if (isIterator)
*isIterator = false; *isIterator = false;
return &container; return &container;
@ -1166,7 +1170,6 @@ const Library::Container* Library::detectContainerInternal(const Token* typeStar
break; break;
} }
} }
}
return nullptr; return nullptr;
} }