Fixed #3212 (Simplify the double pointer cast)
This commit is contained in:
parent
5025d1019f
commit
3ae96600b5
|
@ -5319,11 +5319,10 @@ void Tokenizer::simplifyCasts()
|
|||
tok = tok->linkAt(2);
|
||||
continue;
|
||||
}
|
||||
|
||||
while (Token::Match(tok->next(), "( %type% *| ) *|&| %var%") ||
|
||||
Token::Match(tok->next(), "( %type% %type% *| ) *|&| %var%") ||
|
||||
(!tok->isName() && (Token::Match(tok->next(), "( %type% * ) (") ||
|
||||
Token::Match(tok->next(), "( %type% %type% * ) (")))) {
|
||||
while (Token::Match(tok->next(), "( %type% *| *| *| ) *|&| %var%") ||
|
||||
Token::Match(tok->next(), "( %type% %type% *| *| *| ) *|&| %var%") ||
|
||||
(!tok->isName() && (Token::Match(tok->next(), "( %type% * *| *| ) (") ||
|
||||
Token::Match(tok->next(), "( %type% %type% * *| *| ) (")))) {
|
||||
if (tok->isName() && tok->str() != "return")
|
||||
break;
|
||||
|
||||
|
|
|
@ -260,6 +260,7 @@ private:
|
|||
TEST_CASE(realloc12);
|
||||
TEST_CASE(realloc13);
|
||||
TEST_CASE(realloc14);
|
||||
TEST_CASE(realloc15);
|
||||
|
||||
TEST_CASE(assign1);
|
||||
TEST_CASE(assign2); // #2806 - FP when using redundant assignment
|
||||
|
@ -2728,6 +2729,17 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void realloc15() {
|
||||
check("bool foo() {\n"
|
||||
" char ** m_options;\n"
|
||||
" m_options = (char**)realloc( m_options, 2 * sizeof(char*));\n"
|
||||
" if( m_options == NULL )\n"
|
||||
" return false;\n"
|
||||
" return true;\n"
|
||||
"}\n", false);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Common realloc mistake: \'m_options\' nulled but not freed upon failure\n", errout.str());
|
||||
}
|
||||
|
||||
void assign1() {
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
|
|
|
@ -67,6 +67,8 @@ private:
|
|||
TEST_CASE(removeCast4);
|
||||
TEST_CASE(removeCast5);
|
||||
TEST_CASE(removeCast6);
|
||||
TEST_CASE(removeCast7);
|
||||
TEST_CASE(removeCast8);
|
||||
|
||||
TEST_CASE(inlineasm);
|
||||
|
||||
|
@ -727,6 +729,14 @@ private:
|
|||
ASSERT_EQUALS("if ( ! x )", tokenizeAndStringify("if (x == (char *) ((void *)0))", true));
|
||||
}
|
||||
|
||||
void removeCast7() {
|
||||
ASSERT_EQUALS("str = malloc ( 3 )", tokenizeAndStringify("str=(char **)malloc(3)", true));
|
||||
}
|
||||
|
||||
void removeCast8() {
|
||||
ASSERT_EQUALS("ptr1 = ptr2", tokenizeAndStringify("ptr1=(int * **)ptr2", true));
|
||||
}
|
||||
|
||||
void inlineasm() {
|
||||
ASSERT_EQUALS("; asm ( ) ;", tokenizeAndStringify(";asm { mov ax,bx };"));
|
||||
ASSERT_EQUALS("; asm ( ) ;", tokenizeAndStringify(";_asm { mov ax,bx };"));
|
||||
|
|
Loading…
Reference in New Issue