From 86f852cd76cf92a4b08b59b127cc954420f95744 Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Mon, 31 Jul 2023 13:53:16 -0700 Subject: share more code between the C examples --- c/examples/zero_init/dietpass.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'c/examples/zero_init') 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 #include #include +#include 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); -- cgit v1.2.3