Issue 9255: Prevent infinite recursion in parsedecl (#2134)

This commit is contained in:
Ken-Patrick 2019-09-01 11:36:02 +02:00 committed by Daniel Marjamäki
parent 9ef64eb33e
commit 2c656d6586
2 changed files with 23 additions and 1 deletions

View File

@ -5271,6 +5271,7 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
static const Token * parsedecl(const Token *type, ValueType * const valuetype, ValueType::Sign defaultSignedness, const Settings* settings)
{
const Token * const previousType = type;
const unsigned int pointer0 = valuetype->pointer;
while (Token::Match(type->previous(), "%name%"))
type = type->previous();
@ -5305,7 +5306,7 @@ static const Token * parsedecl(const Token *type, ValueType * const valuetype, V
valuetype->sign = ValueType::Sign::UNSIGNED;
if (valuetype->type == ValueType::Type::UNKNOWN_TYPE &&
type->type() && type->type()->isTypeAlias() && type->type()->typeStart &&
type->type()->typeStart->str() != type->str())
type->type()->typeStart->str() != type->str() && type->type()->typeStart != previousType)
parsedecl(type->type()->typeStart, valuetype, defaultSignedness, settings);
else if (type->str() == "const")
valuetype->constness |= (1 << (valuetype->pointer - pointer0));

View File

@ -396,6 +396,8 @@ private:
TEST_CASE(auto12); // #8993 - const std::string &x; auto y = x; if (y.empty()) ..
TEST_CASE(unionWithConstructor);
TEST_CASE(incomplete_type); // #9255 (infinite recursion)
}
void array() {
@ -7073,6 +7075,25 @@ private:
f = Token::findsimplematch(tokenizer.tokens(), "Fred ( float");
ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 3);
}
void incomplete_type() {
GET_SYMBOL_DB("template<class _Ty,\n"
" class _Alloc = std::allocator<_Ty>>\n"
" class SLSurfaceLayerData\n"
" : public _Vector_alloc<_Vec_base_types<_Ty, _Alloc>>\n"
"{ // varying size array of values\n"
"\n"
" using reverse_iterator = _STD reverse_iterator<iterator>;\n"
" using const_reverse_iterator = _STD reverse_iterator<const_iterator>;\n"
" const_reverse_iterator crend() const noexcept\n"
" { // return iterator for end of reversed nonmutable sequence\n"
" return (rend());\n"
" }\n"
"};");
(void)db;
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestSymbolDatabase)