Skip to content

Commit d3bd373

Browse files
committed
Fixed danmar#5131 (False Positive: %u in format string requires 'unsigned int' but the argument type is 'int'.)
1 parent 352c459 commit d3bd373

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

lib/tokenize.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6075,18 +6075,14 @@ void Tokenizer::simplifyInitVar()
60756075
while (tok1->str() != ",")
60766076
tok1 = tok1->next();
60776077
tok1->str(";");
6078-
Token *tok2 = tok;
6078+
unsigned int num = 0;
6079+
const Token *tok2 = tok;
60796080
if (Token::Match(tok2, "class|struct|union")) {
6080-
tok1->insertToken(tok2->str());
6081-
tok1 = tok1->next();
6081+
num++;
60826082
tok2 = tok2->next();
60836083
}
6084-
tok1->insertToken(tok2->str());
6085-
tok1 = tok1->next();
6086-
tok2 = tok2->next();
6087-
if (tok2->str() == "*") {
6088-
tok1->insertToken("*");
6089-
}
6084+
num++;
6085+
list.insertTokens(tok1, tok, num);
60906086
tok = initVar(tok);
60916087
}
60926088
}

test/testtokenize.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ class TestTokenizer : public TestFixture {
432432

433433
TEST_CASE(labels);
434434
TEST_CASE(simplifyInitVar);
435+
TEST_CASE(simplifyInitVar2);
436+
TEST_CASE(simplifyInitVar3);
435437

436438
TEST_CASE(bitfields1);
437439
TEST_CASE(bitfields2);
@@ -7136,6 +7138,25 @@ class TestTokenizer : public TestFixture {
71367138
}
71377139
}
71387140

7141+
void simplifyInitVar2() {
7142+
// ticket #5131 - unsigned
7143+
const char code[] = "void f() {\n"
7144+
" unsigned int a(0),b(0);\n"
7145+
"}";
7146+
ASSERT_EQUALS("void f ( ) {\n"
7147+
"unsigned int a ; a = 0 ; unsigned int b ; b = 0 ;\n"
7148+
"}", tokenizeAndStringify(code));
7149+
}
7150+
7151+
void simplifyInitVar3() {
7152+
const char code[] = "void f() {\n"
7153+
" int *a(0),b(0);\n"
7154+
"}";
7155+
ASSERT_EQUALS("void f ( ) {\n"
7156+
"int * a ; a = 0 ; int b ; b = 0 ;\n"
7157+
"}", tokenizeAndStringify(code));
7158+
}
7159+
71397160
void bitfields1() {
71407161
const char code1[] = "struct A { bool x : 1; };";
71417162
ASSERT_EQUALS("struct A { bool x ; } ;", tokenizeAndStringify(code1,false));

0 commit comments

Comments
 (0)