From f3ac3d77228648120d2f7b9105669912350d2ced Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Fri, 20 Oct 2023 14:06:54 -0500 Subject: [PATCH] fix: prevent seg fault by not accessing nonexistent ref --- src/forge/config.nim | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/forge/config.nim b/src/forge/config.nim index 6405e24..72ea83a 100644 --- a/src/forge/config.nim +++ b/src/forge/config.nim @@ -26,20 +26,26 @@ proc `$`*(c: ForgeConfig): string = lines.join("\n") -proc loadConfigFile*(f: string, load_targets: bool, - load_bins: bool): ForgeConfig = - let - dict = loadConfig(f) - base = dict.getOrDefault("") +proc loadConfigFile*( + f: string, + load_targets: bool, + load_bins: bool + ): ForgeConfig = + + let dict = loadConfig(f) + + # get the top level flags + if dict.hasKey(""): + let base = dict[""] + result.nimble = base.hasKey("nimble") + result.outdir = base.getOrDefault("outdir") + result.name = base.getOrDefault("name") + result.version = base.getOrDefault("version") + result.format = base.getOrDefault("format") result.targets = newOrderedTable[string, string]() result.bins = newOrderedTable[string, string]() - result.nimble = base.hasKey("nimble") - result.outdir = base.getOrDefault("outdir") - result.name = base.getOrDefault("name") - result.version = base.getOrDefault("version") - result.format = base.getOrDefault("format") if dict.hasKey("target") and load_targets: result.targets = dict.getOrDefault("target") if dict.hasKey("bin") and load_bins: