From d3bd373798ccd169d9ca486bb07cda9679cde0a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 31 Oct 2013 17:20:00 +0100 Subject: [PATCH] Fixed #5131 (False Positive: %u in format string requires 'unsigned int' but the argument type is 'int'.) --- lib/tokenize.cpp | 14 +++++--------- test/testtokenize.cpp | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2a0c6f89e..31014aa79 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6075,18 +6075,14 @@ void Tokenizer::simplifyInitVar() while (tok1->str() != ",") tok1 = tok1->next(); tok1->str(";"); - Token *tok2 = tok; + unsigned int num = 0; + const Token *tok2 = tok; if (Token::Match(tok2, "class|struct|union")) { - tok1->insertToken(tok2->str()); - tok1 = tok1->next(); + num++; tok2 = tok2->next(); } - tok1->insertToken(tok2->str()); - tok1 = tok1->next(); - tok2 = tok2->next(); - if (tok2->str() == "*") { - tok1->insertToken("*"); - } + num++; + list.insertTokens(tok1, tok, num); tok = initVar(tok); } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 2ef6d860e..bb6609d8b 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -432,6 +432,8 @@ private: TEST_CASE(labels); TEST_CASE(simplifyInitVar); + TEST_CASE(simplifyInitVar2); + TEST_CASE(simplifyInitVar3); TEST_CASE(bitfields1); TEST_CASE(bitfields2); @@ -7136,6 +7138,25 @@ private: } } + void simplifyInitVar2() { + // ticket #5131 - unsigned + const char code[] = "void f() {\n" + " unsigned int a(0),b(0);\n" + "}"; + ASSERT_EQUALS("void f ( ) {\n" + "unsigned int a ; a = 0 ; unsigned int b ; b = 0 ;\n" + "}", tokenizeAndStringify(code)); + } + + void simplifyInitVar3() { + const char code[] = "void f() {\n" + " int *a(0),b(0);\n" + "}"; + ASSERT_EQUALS("void f ( ) {\n" + "int * a ; a = 0 ; int b ; b = 0 ;\n" + "}", tokenizeAndStringify(code)); + } + void bitfields1() { const char code1[] = "struct A { bool x : 1; };"; ASSERT_EQUALS("struct A { bool x ; } ;", tokenizeAndStringify(code1,false));