Fixing #3515 (Add samples/id/good|bad.cpp)

http://sourceforge.net/apps/trac/cppcheck/ticket/3515
This commit is contained in:
Reijo Tomperi 2012-01-22 15:52:31 +02:00
parent 6cac600d37
commit 5bb956b0ff
13 changed files with 120 additions and 0 deletions

View File

@ -29,4 +29,5 @@ astyle $style $options test/*.h
astyle $style $options tools/*.cpp
astyle $style $options --recursive "samples/*.c"
astyle $style $options --recursive "samples/*.cpp"

View File

@ -0,0 +1,9 @@
int main()
{
int a[2];
a[0] = 0;
a[1] = 0;
a[2] = 0;
return a[0];
}

View File

@ -0,0 +1,9 @@
int main()
{
int a[3];
a[0] = 0;
a[1] = 0;
a[2] = 0;
return a[0];
}

View File

@ -0,0 +1,12 @@
void foo(int **a)
{
int b = 1;
*a = &b;
}
int main()
{
int *c;
foo(&c);
}

View File

@ -0,0 +1,13 @@
void foo(int **a)
{
int b = 1;
**a = b;
}
int main()
{
int b;
int *c = &b;
foo(&c);
}

View File

@ -0,0 +1,9 @@
int main()
{
int a[2];
int i;
for (i = 0; i < 3; i++)
a[i] = 0;
return a[0];
}

View File

@ -0,0 +1,9 @@
int main()
{
int a[3];
int i;
for (i = 0; i < 3; i++)
a[i] = 0;
return a[0];
}

15
samples/erase/bad.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <vector>
int main()
{
std::vector<int> items;
items.push_back(1);
items.push_back(2);
items.push_back(3);
std::vector<int>::iterator iter;
for (iter=items.begin() ; iter!=items.end() ; ++iter) {
if (true) {
items.erase(iter);
}
}
}

17
samples/erase/good.cpp Normal file
View File

@ -0,0 +1,17 @@
#include <vector>
int main()
{
std::vector<int> items;
items.push_back(1);
items.push_back(2);
items.push_back(3);
std::vector<int>::iterator iter;
for (iter=items.begin(); iter!= items.end();) {
if (true) {
iter = items.erase(iter);
} else {
++iter;
}
}
}

View File

@ -0,0 +1,7 @@
#include <stdio.h>
int main()
{
char str[5];
snprintf(str, 10, "%s", "abc");
}

View File

@ -0,0 +1,7 @@
#include <stdio.h>
int main()
{
char str[10];
snprintf(str, 10, "%s", "abc");
}

View File

@ -0,0 +1,6 @@
int main()
{
#ifndef A
}
#endif

View File

@ -0,0 +1,6 @@
int main()
{
#ifndef A
#endif
}