diff --git a/runastyle b/runastyle index 135a4419e..8c610835a 100755 --- a/runastyle +++ b/runastyle @@ -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" diff --git a/samples/arrayIndexOutOfBounds/bad.c b/samples/arrayIndexOutOfBounds/bad.c new file mode 100644 index 000000000..a71f2b151 --- /dev/null +++ b/samples/arrayIndexOutOfBounds/bad.c @@ -0,0 +1,9 @@ +int main() +{ + int a[2]; + a[0] = 0; + a[1] = 0; + a[2] = 0; + return a[0]; +} + diff --git a/samples/arrayIndexOutOfBounds/good.c b/samples/arrayIndexOutOfBounds/good.c new file mode 100644 index 000000000..825ebcf49 --- /dev/null +++ b/samples/arrayIndexOutOfBounds/good.c @@ -0,0 +1,9 @@ +int main() +{ + int a[3]; + a[0] = 0; + a[1] = 0; + a[2] = 0; + return a[0]; +} + diff --git a/samples/autoVariables/bad.c b/samples/autoVariables/bad.c new file mode 100644 index 000000000..f7f64a7a9 --- /dev/null +++ b/samples/autoVariables/bad.c @@ -0,0 +1,12 @@ +void foo(int **a) +{ + int b = 1; + *a = &b; +} + +int main() +{ + int *c; + foo(&c); +} + diff --git a/samples/autoVariables/good.c b/samples/autoVariables/good.c new file mode 100644 index 000000000..1c8732e2b --- /dev/null +++ b/samples/autoVariables/good.c @@ -0,0 +1,13 @@ +void foo(int **a) +{ + int b = 1; + **a = b; +} + +int main() +{ + int b; + int *c = &b; + foo(&c); +} + diff --git a/samples/bufferAccessOutOfBounds/bad.c b/samples/bufferAccessOutOfBounds/bad.c new file mode 100644 index 000000000..88708c3e0 --- /dev/null +++ b/samples/bufferAccessOutOfBounds/bad.c @@ -0,0 +1,9 @@ +int main() +{ + int a[2]; + int i; + for (i = 0; i < 3; i++) + a[i] = 0; + return a[0]; +} + diff --git a/samples/bufferAccessOutOfBounds/good.c b/samples/bufferAccessOutOfBounds/good.c new file mode 100644 index 000000000..244854764 --- /dev/null +++ b/samples/bufferAccessOutOfBounds/good.c @@ -0,0 +1,9 @@ +int main() +{ + int a[3]; + int i; + for (i = 0; i < 3; i++) + a[i] = 0; + return a[0]; +} + diff --git a/samples/erase/bad.cpp b/samples/erase/bad.cpp new file mode 100644 index 000000000..9e83d1ad3 --- /dev/null +++ b/samples/erase/bad.cpp @@ -0,0 +1,15 @@ +#include +int main() +{ + std::vector items; + items.push_back(1); + items.push_back(2); + items.push_back(3); + std::vector::iterator iter; + for (iter=items.begin() ; iter!=items.end() ; ++iter) { + if (true) { + items.erase(iter); + } + } +} + diff --git a/samples/erase/good.cpp b/samples/erase/good.cpp new file mode 100644 index 000000000..1049075ca --- /dev/null +++ b/samples/erase/good.cpp @@ -0,0 +1,17 @@ +#include +int main() +{ + std::vector items; + items.push_back(1); + items.push_back(2); + items.push_back(3); + std::vector::iterator iter; + for (iter=items.begin(); iter!= items.end();) { + if (true) { + iter = items.erase(iter); + } else { + ++iter; + } + } +} + diff --git a/samples/outOfBounds/bad.c b/samples/outOfBounds/bad.c new file mode 100644 index 000000000..63f7c4628 --- /dev/null +++ b/samples/outOfBounds/bad.c @@ -0,0 +1,7 @@ +#include +int main() +{ + char str[5]; + snprintf(str, 10, "%s", "abc"); +} + diff --git a/samples/outOfBounds/good.c b/samples/outOfBounds/good.c new file mode 100644 index 000000000..b194f7501 --- /dev/null +++ b/samples/outOfBounds/good.c @@ -0,0 +1,7 @@ +#include +int main() +{ + char str[10]; + snprintf(str, 10, "%s", "abc"); +} + diff --git a/samples/syntaxError/bad.c b/samples/syntaxError/bad.c new file mode 100644 index 000000000..58ed3ff86 --- /dev/null +++ b/samples/syntaxError/bad.c @@ -0,0 +1,6 @@ +int main() +{ +#ifndef A +} +#endif + diff --git a/samples/syntaxError/good.c b/samples/syntaxError/good.c new file mode 100644 index 000000000..be49d773f --- /dev/null +++ b/samples/syntaxError/good.c @@ -0,0 +1,6 @@ +int main() +{ +#ifndef A +#endif +} +