Added list of bugs that cppcheck find (incomplete)

This commit is contained in:
Daniel Marjamäki 2008-02-17 17:22:21 +00:00
parent 0b5e6a55d4
commit a51e012a5a
1 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,57 @@
List of bugs that c++check finds
Buffer overrun:
// using numeric array index
char str[100];
str[100] = 0;
// using constant array index
char str2[SIZE];
str[SIZE] = 0;
// Calculating array index with constants and numbers
int i[100];
i[sizeof(i)-1] = 0;
// In some cases, it's detected when a variable causes buffer overrun:
char str[100];
for (int i = 0; i <= 100; i++)
str[i] = 0;
// Using 'strcpy' and 'strcat' can result in buffer overrun..
char str[3];
strcpy(str, "abc");
Memory leaks:
// No deallocation at all
{
Fred *fred = new Fred;
}
// Mismatching allocation / deallocation
char *str = new char[10];
delete str; // Should be 'delete [] str'
// An execution path may prevent a variable from being deallocated:
char *str = new char[10];
if (ab == cd)
return; // or 'continue' or 'break'
Class constructors:
Check that all member variables are initialized.
Check that all private member functions are used.