diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-02-06 10:14:48 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-02-06 10:14:48 -0500 |
commit | 906b120e249c7d73fcd03477bafbdd80ce61b7eb (patch) | |
tree | f728224fa9629085c259714810d6c8033691a7e0 /src/template.c | |
parent | bf3a29fbe20b0b2bd0339c76c3b279cea63b59f2 (diff) | |
download | stasis-906b120e249c7d73fcd03477bafbdd80ce61b7eb.tar.gz |
Fix addressing issue...
* Store the address of the pointer to template variable, instead of the pointer. Whoops!
* Pre-declare all template pointers as early as possible to make them available to the entire program
* Comment tpl_*() prototypes
Diffstat (limited to 'src/template.c')
-rw-r--r-- | src/template.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/template.c b/src/template.c index 335da85..fe7ef11 100644 --- a/src/template.c +++ b/src/template.c @@ -12,12 +12,12 @@ struct tpl_item { char *key; - char *ptr; + char **ptr; }; struct tpl_item *tpl_pool[1024] = {0}; unsigned tpl_pool_used = 0; -void tpl_register(char *key, char *ptr) { +void tpl_register(char *key, char **ptr) { struct tpl_item *item = NULL; item = calloc(1, sizeof(*item)); if (!item) { @@ -47,7 +47,7 @@ char *tpl_getval(char *key) { for (size_t i = 0; i < tpl_pool_used; i++) { if (tpl_pool[i]->key) { if (!strcmp(tpl_pool[i]->key, key)) { - result = tpl_pool[i]->ptr; + result = *tpl_pool[i]->ptr; break; } } @@ -78,8 +78,9 @@ char *tpl_render(char *str) { return NULL; } size_t output_bytes = strlen(str); - char *output; - char *b_close, *pos; + char *output = NULL; + char *b_close = NULL; + char *pos = NULL; pos = str; output = calloc(output_bytes + 1, sizeof(*output)); |