Skip to content

Commit

Permalink
fix(kconfig): Correctly handle integer conversions from map interface (
Browse files Browse the repository at this point in the history
…#752)

Reviewed-by: Jakub Ciolek <jakub@unikraft.io>
Approved-by: Jakub Ciolek <jakub@unikraft.io>
  • Loading branch information
jake-ciolek authored Aug 30, 2023
2 parents 7eb131c + 67ec0ee commit 6182f31
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion kconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ func NewKeyValueMapFromSlice(values ...interface{}) KeyValueMap {
mapping := KeyValueMap{}

for _, value := range values {
str := fmt.Sprintf("%s", value)
var str string
switch t := value.(type) {
case string:
str = t
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
str = fmt.Sprintf("%d", t)
}
tokens := strings.SplitN(str, "=", 2)
if len(tokens) > 1 {
mapping[tokens[0]] = &KeyValue{
Expand Down Expand Up @@ -57,6 +63,8 @@ func NewKeyValueMapFromMap(values map[string]interface{}) KeyValueMap {
v = "y"
}
mapping[key].Value = v
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
mapping[key].Value = fmt.Sprintf("%d", casting)
default:
mapping[key].Value = fmt.Sprintf("%s", casting)
}
Expand Down

0 comments on commit 6182f31

Please sign in to comment.