Skip to content

Commit a84a5a6

Browse files
Add tests for #11152, #13579 (#8571)
1 parent b82e866 commit a84a5a6

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

test/testtokenize.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ class TestTokenizer : public TestFixture {
479479
TEST_CASE(cppKeywordInCSource);
480480

481481
TEST_CASE(cppcast);
482+
TEST_CASE(ccast);
482483

483484
TEST_CASE(checkHeader1);
484485

@@ -8418,6 +8419,19 @@ class TestTokenizer : public TestFixture {
84188419
}
84198420
}
84208421

8422+
void ccast() {
8423+
const char code[] = "a = (int)x;\n" // #13579
8424+
"int (*p)[10];\n";
8425+
8426+
SimpleTokenizer tokenizer(settingsDefault, *this);
8427+
ASSERT(tokenizer.tokenize(code));
8428+
8429+
const Token* par = Token::findsimplematch(tokenizer.tokens(), "(");
8430+
ASSERT(par->isCast());
8431+
par = Token::findsimplematch(par->next(), "(");
8432+
ASSERT(!par->isCast());
8433+
}
8434+
84218435
#define checkHdrs(...) checkHdrs_(__FILE__, __LINE__, __VA_ARGS__)
84228436
template<size_t size>
84238437
std::string checkHdrs_(const char* file, int line, const char (&code)[size], bool checkHeadersFlag) {

test/testvalueflow.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6290,6 +6290,14 @@ class TestValueFlow : public TestFixture {
62906290
"}\n";
62916291
values = tokenValues(code, "x > 5", ValueFlow::Value::ValueType::UNINIT);
62926292
ASSERT_EQUALS(0, values.size());
6293+
6294+
code = "void f() {\n" // #11152
6295+
" char b[10];\n"
6296+
" sprintf(b, \"abc\");\n"
6297+
" printf(\"%s\", b);\n"
6298+
"}\n";
6299+
values = tokenValues(code, "b )", ValueFlow::Value::ValueType::UNINIT);
6300+
ASSERT_EQUALS(0, values.size());
62936301
}
62946302

62956303
void valueFlowConditionExpressions() {

0 commit comments

Comments
 (0)