Skip to content

Commit 85f7393

Browse files
committed
newt: Fix config check crashes
We should use DeepEqual to compare interface values. In some cases Value interface might contain a map with some more keys than just "value" key - for example "description" key. This will cause DeepEqual to fail, even if the "value" keys would be the same. However before returning an error we also check if Expr field of both entries is not nil. We can assume that in that case no additional keys in map will be present and no false positive error will be returned.
1 parent c7afc5f commit 85f7393

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

.github/workflows/test_ambiguous_cfg.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ jobs:
6363
cp -r .github/targets/ambiguous_fail project/targets
6464
cd project/
6565
! newt build ambiguous_fail &> tmp.txt
66-
grep "Error: Setting CONSOLE_IMPLEMENTATION collision - two conditions true:" tmp.txt -q
66+
grep "Error: setting CONSOLE_IMPLEMENTATION collision - two conditions true:" tmp.txt -q

newt/ycfg/ycfg.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package ycfg
2222
import (
2323
"fmt"
2424
"mynewt.apache.org/newt/newt/cfgv"
25+
"reflect"
2526
"strings"
2627

2728
"github.com/spf13/cast"
@@ -470,8 +471,8 @@ func (yc *YCfg) GetStringMap(
470471
}
471472

472473
if _, exists := result[k]; exists {
473-
if (entry.Value != result[k].Value) && (result[k].Expr != nil) {
474-
return nil, fmt.Errorf("Setting %s collision - two conditions true:\n[%s, %s]\n"+
474+
if !reflect.DeepEqual(entry.Value, result[k].Value) && (result[k].Expr != nil) && (entry.Expr != nil) {
475+
return nil, fmt.Errorf("setting %s collision - two conditions true:\n[%s, %s]\n"+
475476
"Conflicting file: %s",
476477
k, entry.Expr.String(), result[k].Expr.String(), yc.name)
477478
}

0 commit comments

Comments
 (0)