cppcheck/bugs_that_cppcheck_finds.txt

58 lines
1.1 KiB
Plaintext

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.