diff options
Diffstat (limited to 'tests/hello_world_loop_malloc.cpp')
-rw-r--r-- | tests/hello_world_loop_malloc.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/hello_world_loop_malloc.cpp b/tests/hello_world_loop_malloc.cpp new file mode 100644 index 00000000..b9361834 --- /dev/null +++ b/tests/hello_world_loop_malloc.cpp @@ -0,0 +1,21 @@ +#include<stdio.h> +#include<string.h> +#include<stdlib.h> + +extern "C" { + void dump(char *s) { + printf("%s\n", s); + } +} + +int main() { + char *original = (char*)"h e l l o , w o r l d ! "; + char *copy = (char*)malloc(strlen(original)); + for (int i = 0; i < strlen(original); i += 2) { + copy[i/2] = original[i]; + } + copy[strlen(copy)+1] = (int)&original; // force original to be on the stack + dump(copy); + return 1; +} + |