Test that there is no segfault in CheckOther::checkZeroDivisionOrUselessCondition when the SymbolDatabase is invalid. Ticket: #5045

This commit is contained in:
Daniel Marjamäki 2013-10-10 22:23:52 +02:00
parent 6eaa2f2444
commit 783bb6eb0b
1 changed files with 44 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include "checkother.h"
#include "testsuite.h"
#include <sstream>
#include <symboldatabase.h>
extern std::ostringstream errout;
@ -532,6 +533,49 @@ private:
"double* pp[3] = {p1,p2,p3};\n"
"}");
ASSERT_EQUALS("", errout.str());
// ticket #5045 segmentation fault when SymbolDatabase is corrupt
{
// We don't use the "check" function because we need to
// make sure the symboldatabase is inconsistent..
const char code[] = "namespace {\n"
" void get() { source = create(context); }\n"
" void create( something const & context)\n"
" SAL_THROW((css::uno::Exception))\n"
" { return new Server(context); }\n"
"}\n"
"void component_getFactory()\n"
"{ component_getFactoryHelper(); }";
Settings settings;
settings.addEnabled("warning");
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
tokenizer.tokenize(istr,"test.cpp");
tokenizer.simplifyTokenList();
// Assert that the symboldatabase is inconsistent..
const SymbolDatabase *symbolDatabase = tokenizer.getSymbolDatabase();
ASSERT_EQUALS(2U, symbolDatabase->getVariableListSize());
const Variable *var = symbolDatabase->getVariableFromVarId(1U);
ASSERT(var->typeStartToken());
bool invalid = true;
for (const Token *tok = var->typeStartToken(); tok; tok = tok->next()) {
invalid = true;
if (tok == var->typeEndToken()) {
invalid = false;
break;
}
}
ASSERT_EQUALS(true, invalid);
// Make sure there is no crash with inconsistent symboldatabase..
// typeStartToken() is not before typeEndToken()
errout.str("");
CheckOther checkOther(&tokenizer, &settings, this);
checkOther.checkZeroDivisionOrUselessCondition(); // don't crash
}
}
void nanInArithmeticExpression() {