diff options
Diffstat (limited to 'c/examples/zero_init')
-rw-r--r-- | c/examples/zero_init/dietpass.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/c/examples/zero_init/dietpass.c b/c/examples/zero_init/dietpass.c index e145a91..962337c 100644 --- a/c/examples/zero_init/dietpass.c +++ b/c/examples/zero_init/dietpass.c @@ -3,6 +3,7 @@ #include <stdlib.h> #include <string.h> #include <libdietc.h> +#include <string_helpers.c> int main(int argc, char **argv) { assert(argc == 2); @@ -12,12 +13,8 @@ int main(int argc, char **argv) { for (struct instruction *i = f->instructions; i; i = i->next) { if (strncmp(i->line, "\tType_", strlen("\tType_"))) continue; char *name = libdietc_tokdup(strchrnul(i->line, ' ') + 1); - struct instruction *n = calloc(1, sizeof(*n)); - n->line = malloc(strlen(name) + 512); - sprintf(n->line, "memset(&%s, 0, sizeof(%s));", name, name); - n->next = i->next; - i->next = n; - i = n; + char *line = sbuild("memset(&%s, 0, sizeof(%s));", name, name); + i = libdietc_insert_after(i, line); } } libdietc_print(program); |