Skip to content

Commit 5bb956b

Browse files
committed
1 parent 6cac600 commit 5bb956b

File tree

13 files changed

+120
-0
lines changed

13 files changed

+120
-0
lines changed

runastyle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ astyle $style $options test/*.h
2929

3030
astyle $style $options tools/*.cpp
3131
astyle $style $options --recursive "samples/*.c"
32+
astyle $style $options --recursive "samples/*.cpp"
3233

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int main()
2+
{
3+
int a[2];
4+
a[0] = 0;
5+
a[1] = 0;
6+
a[2] = 0;
7+
return a[0];
8+
}
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int main()
2+
{
3+
int a[3];
4+
a[0] = 0;
5+
a[1] = 0;
6+
a[2] = 0;
7+
return a[0];
8+
}
9+

samples/autoVariables/bad.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void foo(int **a)
2+
{
3+
int b = 1;
4+
*a = &b;
5+
}
6+
7+
int main()
8+
{
9+
int *c;
10+
foo(&c);
11+
}
12+

samples/autoVariables/good.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
void foo(int **a)
2+
{
3+
int b = 1;
4+
**a = b;
5+
}
6+
7+
int main()
8+
{
9+
int b;
10+
int *c = &b;
11+
foo(&c);
12+
}
13+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int main()
2+
{
3+
int a[2];
4+
int i;
5+
for (i = 0; i < 3; i++)
6+
a[i] = 0;
7+
return a[0];
8+
}
9+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int main()
2+
{
3+
int a[3];
4+
int i;
5+
for (i = 0; i < 3; i++)
6+
a[i] = 0;
7+
return a[0];
8+
}
9+

samples/erase/bad.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <vector>
2+
int main()
3+
{
4+
std::vector<int> items;
5+
items.push_back(1);
6+
items.push_back(2);
7+
items.push_back(3);
8+
std::vector<int>::iterator iter;
9+
for (iter=items.begin() ; iter!=items.end() ; ++iter) {
10+
if (true) {
11+
items.erase(iter);
12+
}
13+
}
14+
}
15+

samples/erase/good.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <vector>
2+
int main()
3+
{
4+
std::vector<int> items;
5+
items.push_back(1);
6+
items.push_back(2);
7+
items.push_back(3);
8+
std::vector<int>::iterator iter;
9+
for (iter=items.begin(); iter!= items.end();) {
10+
if (true) {
11+
iter = items.erase(iter);
12+
} else {
13+
++iter;
14+
}
15+
}
16+
}
17+

samples/outOfBounds/bad.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdio.h>
2+
int main()
3+
{
4+
char str[5];
5+
snprintf(str, 10, "%s", "abc");
6+
}
7+

0 commit comments

Comments
 (0)