Fix nil pointer dereference cause by accessing the last used input without checking its existence

pull/71/head
Nicu Reut 3 years ago
parent 306cd40791
commit 43b50806e7

@ -21,7 +21,7 @@ const configFile = "config.toml"
func initializeConfigIfNot() {
log.Println("Checking if config needs to be initialized")
conf := config{Threshold: 95, DisplayMonitorSources: false, EnableUpdates: true} // if you're a package maintainer and you mess with this, we have a problem.
conf := config{Threshold: 95, DisplayMonitorSources: false, EnableUpdates: true, LastUsedInput: nil} // if you're a package maintainer and you mess with this, we have a problem.
// Unless you set -tags release on the build the updater is *not* compiled in any. DO NOT MESS WITH THIS!
// This isn't and never was the proper location to disable the updater.

@ -246,9 +246,12 @@ func getSourcesWithPreSelectedInput(ctx *ntcontext) []input {
inputs := getSources(ctx.paClient)
preselectedInputId := ctx.config.LastUsedInput
inputExists := false
for _, input := range inputs {
inputExists = inputExists || input.ID == *preselectedInputId
if preselectedInputId != nil {
for _, input := range inputs {
inputExists = inputExists || input.ID == *preselectedInputId
}
}
if !inputExists {
defaultSource, err := getDefaultSourceID(ctx.paClient)
if err != nil {

Loading…
Cancel
Save