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") lines.join("\n")
proc loadConfigFile*(f: string, load_targets: bool, proc loadConfigFile*(
load_bins: bool): ForgeConfig = f: string,
let load_targets: bool,
dict = loadConfig(f) load_bins: bool
base = dict.getOrDefault("") ): ForgeConfig =
result.targets = newOrderedTable[string, string]() let dict = loadConfig(f)
result.bins = newOrderedTable[string, string]()
# get the top level flags
if dict.hasKey(""):
let base = dict[""]
result.nimble = base.hasKey("nimble") result.nimble = base.hasKey("nimble")
result.outdir = base.getOrDefault("outdir") result.outdir = base.getOrDefault("outdir")
result.name = base.getOrDefault("name") result.name = base.getOrDefault("name")
result.version = base.getOrDefault("version") result.version = base.getOrDefault("version")
result.format = base.getOrDefault("format") result.format = base.getOrDefault("format")
result.targets = newOrderedTable[string, string]()
result.bins = newOrderedTable[string, string]()
if dict.hasKey("target") and load_targets: if dict.hasKey("target") and load_targets:
result.targets = dict.getOrDefault("target") result.targets = dict.getOrDefault("target")
if dict.hasKey("bin") and load_bins: if dict.hasKey("bin") and load_bins: