Refactoring: Split null pointer check into 4 smaller functions.

This commit is contained in:
Reijo Tomperi 2009-10-11 18:10:20 +03:00
parent 1401e3f668
commit 675cc08340
2 changed files with 45 additions and 5 deletions

View File

@ -832,10 +832,7 @@ void CheckOther::strPlusChar()
} }
void CheckOther::nullPointerAfterLoop()
void CheckOther::nullPointer()
{ {
// Locate insufficient null-pointer handling after loop // Locate insufficient null-pointer handling after loop
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
@ -891,7 +888,10 @@ void CheckOther::nullPointer()
tok2 = tok2->next(); tok2 = tok2->next();
} }
} }
}
void CheckOther::nullPointerLinkedList()
{
// looping through items in a linked list in a inner loop.. // looping through items in a linked list in a inner loop..
for (const Token *tok1 = _tokenizer->tokens(); tok1; tok1 = tok1->next()) for (const Token *tok1 = _tokenizer->tokens(); tok1; tok1 = tok1->next())
{ {
@ -969,6 +969,10 @@ void CheckOther::nullPointer()
} }
} }
} }
}
void CheckOther::nullPointerStructByDeRefAndChec()
{
// Dereferencing a struct pointer and then checking if it's NULL.. // Dereferencing a struct pointer and then checking if it's NULL..
for (const Token *tok1 = _tokenizer->tokens(); tok1; tok1 = tok1->next()) for (const Token *tok1 = _tokenizer->tokens(); tok1; tok1 = tok1->next())
@ -1047,6 +1051,10 @@ void CheckOther::nullPointer()
} }
} }
}
void CheckOther::nullPointerByDeRefAndChec()
{
// Dereferencing a pointer and then checking if it's NULL.. // Dereferencing a pointer and then checking if it's NULL..
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
@ -1093,7 +1101,13 @@ void CheckOther::nullPointer()
} }
} }
void CheckOther::nullPointer()
{
nullPointerAfterLoop();
nullPointerLinkedList();
nullPointerStructByDeRefAndChec();
nullPointerByDeRefAndChec();
}
void CheckOther::checkZeroDivision() void CheckOther::checkZeroDivision()
{ {

View File

@ -202,6 +202,32 @@ public:
// optimisations // optimisations
" * optimisation: detect post increment/decrement\n"; " * optimisation: detect post increment/decrement\n";
} }
private:
/**
* Does one part of the check for nullPointer().
* Locate insufficient null-pointer handling after loop
*/
void nullPointerAfterLoop();
/**
* Does one part of the check for nullPointer().
* looping through items in a linked list in a inner loop..
*/
void nullPointerLinkedList();
/**
* Does one part of the check for nullPointer().
* Dereferencing a struct pointer and then checking if it's NULL..
*/
void nullPointerStructByDeRefAndChec();
/**
* Does one part of the check for nullPointer().
* Dereferencing a pointer and then checking if it's NULL..
*/
void nullPointerByDeRefAndChec();
}; };
/// @} /// @}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------