fix: prevent seg fault by not accessing nonexistent ref

This commit is contained in:
Daylin Morgan 2023-10-20 14:06:54 -05:00
parent c71d50dc9b
commit f3ac3d7722
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -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: