testsuite: Add x-flow tests

This commit is contained in:
Daniel Marjamäki 2019-12-15 13:57:27 +01:00
parent f614d32d6a
commit aee9519d21
6 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,16 @@
#include <stdlib.h>
// 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;
}

View File

@ -0,0 +1,17 @@
#include <stdlib.h>
// 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;
}

View File

@ -0,0 +1,19 @@
#include <stdlib.h>
// 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;
}

View File

@ -0,0 +1,18 @@
#include <stdlib.h>
// 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;
}

View File

@ -0,0 +1,14 @@
#include <stdlib.h>
#include <string.h>
// Copy string
void f() {
char* buf = (char*) malloc(9);
strcpy(buf, "Too big to fit");
}
int main() {
f();
return 0;
}

View File

@ -0,0 +1,20 @@
#include <stdlib.h>
// 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;
}