Fixed #1975 (segmentation fault of cppcheck)
This commit is contained in:
parent
190a0040b7
commit
427c0f4bfd
|
@ -919,7 +919,7 @@ std::list<std::string> Preprocessor::getcfgs(const std::string &filedata, const
|
||||||
{
|
{
|
||||||
Tokenizer tokenizer(_settings, _errorLogger);
|
Tokenizer tokenizer(_settings, _errorLogger);
|
||||||
std::istringstream tempIstr(s.c_str());
|
std::istringstream tempIstr(s.c_str());
|
||||||
if (!tokenizer.tokenize(tempIstr, filename.c_str()))
|
if (!tokenizer.tokenize(tempIstr, filename.c_str(), "", true))
|
||||||
{
|
{
|
||||||
std::ostringstream lineStream;
|
std::ostringstream lineStream;
|
||||||
lineStream << __LINE__;
|
lineStream << __LINE__;
|
||||||
|
@ -1053,7 +1053,7 @@ void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &v
|
||||||
{
|
{
|
||||||
Tokenizer tokenizer;
|
Tokenizer tokenizer;
|
||||||
std::istringstream istr(("(" + condition + ")").c_str());
|
std::istringstream istr(("(" + condition + ")").c_str());
|
||||||
tokenizer.tokenize(istr, "");
|
tokenizer.tokenize(istr, "", "", true);
|
||||||
|
|
||||||
if (Token::Match(tokenizer.tokens(), "( %var% )"))
|
if (Token::Match(tokenizer.tokens(), "( %var% )"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1695,7 +1695,10 @@ void Tokenizer::simplifyTypedef()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::string &configuration)
|
bool Tokenizer::tokenize(std::istream &code,
|
||||||
|
const char FileName[],
|
||||||
|
const std::string &configuration,
|
||||||
|
const bool preprocessorCondition)
|
||||||
{
|
{
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
|
|
||||||
|
@ -1704,7 +1707,6 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
|
||||||
|
|
||||||
createTokens(code);
|
createTokens(code);
|
||||||
|
|
||||||
|
|
||||||
// remove inline SQL (Oracle PRO*C). Ticket: #1959
|
// remove inline SQL (Oracle PRO*C). Ticket: #1959
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
|
@ -1816,6 +1818,8 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for more complicated syntax errors when using templates..
|
// check for more complicated syntax errors when using templates..
|
||||||
|
if (!preprocessorCondition)
|
||||||
|
{
|
||||||
for (const Token *tok = _tokens; tok; tok = tok->next())
|
for (const Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
// skip executing scopes..
|
// skip executing scopes..
|
||||||
|
@ -1917,6 +1921,7 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Remove "= default|delete" inside class|struct definitions
|
// Remove "= default|delete" inside class|struct definitions
|
||||||
|
@ -2050,10 +2055,13 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
|
||||||
// Change initialisation of variable to assignment
|
// Change initialisation of variable to assignment
|
||||||
simplifyInitVar();
|
simplifyInitVar();
|
||||||
|
|
||||||
|
if (!preprocessorCondition)
|
||||||
|
{
|
||||||
setVarId();
|
setVarId();
|
||||||
|
|
||||||
// Change initialisation of variable to assignment
|
// Change initialisation of variable to assignment
|
||||||
simplifyInitVar();
|
simplifyInitVar();
|
||||||
|
}
|
||||||
|
|
||||||
_tokens->assignProgressValues();
|
_tokens->assignProgressValues();
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,10 @@ public:
|
||||||
* @param configuration E.g. "A" for code where "#ifdef A" is true
|
* @param configuration E.g. "A" for code where "#ifdef A" is true
|
||||||
* @return false if Source code contains syntax errors
|
* @return false if Source code contains syntax errors
|
||||||
*/
|
*/
|
||||||
bool tokenize(std::istream &code, const char FileName[], const std::string &configuration = "");
|
bool tokenize(std::istream &code,
|
||||||
|
const char FileName[],
|
||||||
|
const std::string &configuration = "",
|
||||||
|
const bool preprocessorCondition = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create tokens from code.
|
* Create tokens from code.
|
||||||
|
|
|
@ -110,6 +110,7 @@ private:
|
||||||
TEST_CASE(if_cond8);
|
TEST_CASE(if_cond8);
|
||||||
TEST_CASE(if_cond9);
|
TEST_CASE(if_cond9);
|
||||||
TEST_CASE(if_cond10);
|
TEST_CASE(if_cond10);
|
||||||
|
TEST_CASE(if_cond11);
|
||||||
|
|
||||||
TEST_CASE(if_or_1);
|
TEST_CASE(if_or_1);
|
||||||
TEST_CASE(if_or_2);
|
TEST_CASE(if_or_2);
|
||||||
|
@ -1067,6 +1068,22 @@ private:
|
||||||
preprocessor.preprocess(istr, actual, "file.c");
|
preprocessor.preprocess(istr, actual, "file.c");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void if_cond11()
|
||||||
|
{
|
||||||
|
errout.str("");
|
||||||
|
const char filedata[] = "#if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE\n"
|
||||||
|
"#if LIBGCC2_HAS_DF_MODE\n"
|
||||||
|
"#elif FLT_MANT_DIG < W_TYPE_SIZE\n"
|
||||||
|
"#endif\n"
|
||||||
|
"#endif\n";
|
||||||
|
std::istringstream istr(filedata);
|
||||||
|
std::map<std::string, std::string> actual;
|
||||||
|
Settings settings;
|
||||||
|
Preprocessor preprocessor(&settings, this);
|
||||||
|
preprocessor.preprocess(istr, actual, "file.c");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void if_or_1()
|
void if_or_1()
|
||||||
|
|
Loading…
Reference in New Issue