aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-make/ctx.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2018-07-26 00:47:48 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2018-07-26 00:47:48 +0200
commit00b8de1ca989a0f66517b2a4ccfcc30766f0d669 (patch)
tree9476afdda2e0b7fa431fe88dbc5554a509bcb2df /src/blogc-make/ctx.c
parenteae0bfe730bb4f29f88c609c2562025a9d029256 (diff)
downloadblogc-00b8de1ca989a0f66517b2a4ccfcc30766f0d669.tar.gz
blogc-00b8de1ca989a0f66517b2a4ccfcc30766f0d669.tar.bz2
blogc-00b8de1ca989a0f66517b2a4ccfcc30766f0d669.zip
make: prevent dereferencing segfaults. minor style fixes
Diffstat (limited to 'src/blogc-make/ctx.c')
-rw-r--r--src/blogc-make/ctx.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c
index 0c47c12..16ab9fa 100644
--- a/src/blogc-make/ctx.c
+++ b/src/blogc-make/ctx.c
@@ -220,20 +220,19 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
// can't return null and set error after this!
- const char *template_dir = bc_trie_lookup(settings->settings,
- "template_dir");
+ const char *template_dir = bm_ctx_settings_lookup(rv, "template_dir");
char *main_template = bc_strdup_printf("%s/%s", template_dir,
- bc_trie_lookup(settings->settings, "main_template"));
+ bm_ctx_settings_lookup(rv, "main_template"));
rv->main_template_fctx = bm_filectx_new(rv, main_template, NULL, NULL);
free(main_template);
rv->atom_template_fctx = bm_filectx_new(rv, atom_template, NULL, NULL);
free(atom_template);
- const char *content_dir = bc_trie_lookup(settings->settings, "content_dir");
- const char *post_prefix = bc_trie_lookup(settings->settings, "post_prefix");
- const char *source_ext = bc_trie_lookup(settings->settings, "source_ext");
+ const char *content_dir = bm_ctx_settings_lookup(rv, "content_dir");
+ const char *post_prefix = bm_ctx_settings_lookup(rv, "post_prefix");
+ const char *source_ext = bm_ctx_settings_lookup(rv, "source_ext");
const char *slash = post_prefix[0] == '\0' ? "" : "/";
rv->posts_fctx = NULL;
@@ -354,3 +353,20 @@ bm_ctx_free(bm_ctx_t *ctx)
free(ctx->blogc_runserver);
free(ctx);
}
+
+
+const char*
+bm_ctx_settings_lookup(bm_ctx_t *ctx, const char *key)
+{
+ if (ctx == NULL || ctx->settings == NULL || ctx->settings->settings == NULL)
+ return NULL;
+ return bc_trie_lookup(ctx->settings->settings, key);
+}
+
+
+const char*
+bm_ctx_settings_lookup_str(bm_ctx_t *ctx, const char *key)
+{
+ const char *rv = bm_ctx_settings_lookup(ctx, key);
+ return rv == NULL ? "" : rv;
+}