diff --git a/test/testsuites/x-flow/buffer01.cpp b/test/testsuites/x-flow/buffer01.cpp new file mode 100644 index 000000000..3dc44d62e --- /dev/null +++ b/test/testsuites/x-flow/buffer01.cpp @@ -0,0 +1,16 @@ +#include + +// Simple for loop + +void f() { + char* buf = (char*) malloc(9); + int i; + for (i = 0; i < 12; i++) { + buf[i] = 's'; + } +} + +int main() { + f(); + return 0; +} diff --git a/test/testsuites/x-flow/buffer02.cpp b/test/testsuites/x-flow/buffer02.cpp new file mode 100644 index 000000000..0590d5142 --- /dev/null +++ b/test/testsuites/x-flow/buffer02.cpp @@ -0,0 +1,17 @@ +#include + +// Simple while loop + +void f() { + char* buf = (char*) malloc(9); + int i = 0; + while (i < 12) { + buf[i] = 's'; + i++; + } +} + +int main() { + f(); + return 0; +} diff --git a/test/testsuites/x-flow/buffer03.cpp b/test/testsuites/x-flow/buffer03.cpp new file mode 100644 index 000000000..ec343e4ed --- /dev/null +++ b/test/testsuites/x-flow/buffer03.cpp @@ -0,0 +1,19 @@ +#include + +// Reallocation + +void f() { + char* buf = (char*) malloc(20); + buf[6] = 'x'; + buf = (char*) realloc(buf, 9); + int i = 0; + while (i < 12) { + buf[i] = 's'; + i++; + } +} + +int main() { + f(); + return 0; +} diff --git a/test/testsuites/x-flow/buffer04.cpp b/test/testsuites/x-flow/buffer04.cpp new file mode 100644 index 000000000..4b605c7e0 --- /dev/null +++ b/test/testsuites/x-flow/buffer04.cpp @@ -0,0 +1,18 @@ +#include + +// Nested loops + +void f() { + char* buf = (char*) malloc(9); + int i, j; + for (i = 0; i < 3; i++) { + for (j = 0; j < 6; j++) { + buf[i*j] = 's'; + } + } +} + +int main() { + f(); + return 0; +} diff --git a/test/testsuites/x-flow/buffer05.cpp b/test/testsuites/x-flow/buffer05.cpp new file mode 100644 index 000000000..0fdfaa280 --- /dev/null +++ b/test/testsuites/x-flow/buffer05.cpp @@ -0,0 +1,14 @@ +#include +#include + +// Copy string + +void f() { + char* buf = (char*) malloc(9); + strcpy(buf, "Too big to fit"); +} + +int main() { + f(); + return 0; +} diff --git a/test/testsuites/x-flow/buffer06.cpp b/test/testsuites/x-flow/buffer06.cpp new file mode 100644 index 000000000..010534c0f --- /dev/null +++ b/test/testsuites/x-flow/buffer06.cpp @@ -0,0 +1,20 @@ +#include + +// More complex object + +void f() { + struct Person { + const char* name; + int age; + }; + Person* people = (Person*) malloc(9 * sizeof(Person)); + for (int i = 0; i < 12; i++) { + people[i].name = "John"; + people[i].age = 23; + } +} + +int main() { + f(); + return 0; +}