Skip to content

Commit

Permalink
Fix handling of nil
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Dec 30, 2023
1 parent 64c207f commit f2e2918
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions spine/model/commandframe_additions.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,16 @@ func (f *FilterType) SetDataForFunction(tagType EEBusTagTypeType, fct FunctionTy
break
}

if data == nil || (reflect.ValueOf(data).Kind() == reflect.Ptr && reflect.ValueOf(data).IsNil()) {
typ := reflect.TypeOf(data).Elem()
ff.Set(reflect.New(typ))
return
}

dataV := reflect.ValueOf(data)
dataC := dataV.Convert(ff.Type())
ff.Set(dataC)
return
}
}

Expand Down Expand Up @@ -201,9 +208,16 @@ func (cmd *CmdType) SetDataForFunction(fct FunctionType, data any) {
break
}

if data == nil || (reflect.ValueOf(data).Kind() == reflect.Ptr && reflect.ValueOf(data).IsNil()) {
typ := reflect.TypeOf(data).Elem()
ff.Set(reflect.New(typ))
return
}

dataV := reflect.ValueOf(data)
dataC := dataV.Convert(ff.Type())
ff.Set(dataC)
return
}
}

Expand Down

0 comments on commit f2e2918

Please sign in to comment.