summaryrefslogtreecommitdiff
path: root/c/examples/zero_init
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthew@masot.net>2023-07-31 13:53:16 -0700
committerMatthew Sotoudeh <matthew@masot.net>2023-07-31 13:53:16 -0700
commit86f852cd76cf92a4b08b59b127cc954420f95744 (patch)
tree459eb4b2d7e587a036dd10f1c4c9bc757346e0bd /c/examples/zero_init
parent135b17bada960c4585d5a124fedb7e4e9d849078 (diff)
share more code between the C examplesHEADmaster
Diffstat (limited to 'c/examples/zero_init')
-rw-r--r--c/examples/zero_init/dietpass.c9
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);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback