Skip to content

Commit

Permalink
Add missing nil check for GetOrderedMap accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
wenovus committed Oct 4, 2023
1 parent 23c9aac commit a3588e8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions gogen/gogen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,9 @@ func (s *Tstruct) AppendListWithKey(v *Tstruct_ListWithKey) error {
// is nil, or the specified key is not present in the list, nil is returned
// such that Get* methods may be safely chained.
func (s *Tstruct) GetListWithKey(KeyLeaf string) *Tstruct_ListWithKey {
if s == nil {
return nil
}
key := KeyLeaf
return s.ListWithKey.Get(key)
}
Expand Down
3 changes: 3 additions & 0 deletions gogen/ordered_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func (s *{{ .ParentStructName }}) Get{{ .ListFieldName }}(
{{- if ne (inc $i) $length -}}, {{ end -}}
{{- end -}}
) *{{ .ListTypeName }} {
if s == nil {
return nil
}
{{ if gt (len .Keys) 1 -}}
key := {{ .KeyName }}{
{{- range $key := .Keys }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func (s *Model) AppendSingleKeyOrdered(v *Model_SingleKeyOrdered) error {
// is nil, or the specified key is not present in the list, nil is returned
// such that Get* methods may be safely chained.
func (s *Model) GetSingleKeyOrdered(Key string) *Model_SingleKeyOrdered {
if s == nil {
return nil
}
key := Key
return s.SingleKeyOrdered.Get(key)
}
Expand Down
3 changes: 3 additions & 0 deletions gogen/testdata/structs/openconfig-withlist.formatted-txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func (s *Model) AppendSingleKeyOrdered(v *Model_SingleKeyOrdered) error {
// is nil, or the specified key is not present in the list, nil is returned
// such that Get* methods may be safely chained.
func (s *Model) GetSingleKeyOrdered(Key string) *Model_SingleKeyOrdered {
if s == nil {
return nil
}
key := Key
return s.SingleKeyOrdered.Get(key)
}
Expand Down
15 changes: 12 additions & 3 deletions integration_tests/schemaops/ctestschema/ctestschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ func (s *Device) AppendOrderedList(v *OrderedList) error {
// is nil, or the specified key is not present in the list, nil is returned
// such that Get* methods may be safely chained.
func (s *Device) GetOrderedList(Key string) *OrderedList {
if s == nil {
return nil
}
key := Key
return s.OrderedList.Get(key)
}
Expand All @@ -342,7 +345,7 @@ type OrderedList_OrderedMap struct {
}

// IsYANGOrderedList ensures that OrderedList_OrderedMap implements the
// ygot.GoOrderedList interface.
// ygot.GoOrderedMap interface.
func (*OrderedList_OrderedMap) IsYANGOrderedList() {}

// init initializes any uninitialized values.
Expand Down Expand Up @@ -481,6 +484,9 @@ func (s *Device) AppendOrderedMultikeyedList(v *OrderedMultikeyedList) error {
// is nil, or the specified key is not present in the list, nil is returned
// such that Get* methods may be safely chained.
func (s *Device) GetOrderedMultikeyedList(Key1 string, Key2 uint64) *OrderedMultikeyedList {
if s == nil {
return nil
}
key := OrderedMultikeyedList_Key{
Key1: Key1,
Key2: Key2,
Expand All @@ -507,7 +513,7 @@ type OrderedMultikeyedList_OrderedMap struct {
}

// IsYANGOrderedList ensures that OrderedMultikeyedList_OrderedMap implements the
// ygot.GoOrderedList interface.
// ygot.GoOrderedMap interface.
func (*OrderedMultikeyedList_OrderedMap) IsYANGOrderedList() {}

// init initializes any uninitialized values.
Expand Down Expand Up @@ -782,6 +788,9 @@ func (s *OrderedList) AppendOrderedList(v *OrderedList_OrderedList) error {
// is nil, or the specified key is not present in the list, nil is returned
// such that Get* methods may be safely chained.
func (s *OrderedList) GetOrderedList(Key string) *OrderedList_OrderedList {
if s == nil {
return nil
}
key := Key
return s.OrderedList.Get(key)
}
Expand All @@ -802,7 +811,7 @@ type OrderedList_OrderedList_OrderedMap struct {
}

// IsYANGOrderedList ensures that OrderedList_OrderedList_OrderedMap implements the
// ygot.GoOrderedList interface.
// ygot.GoOrderedMap interface.
func (*OrderedList_OrderedList_OrderedMap) IsYANGOrderedList() {}

// init initializes any uninitialized values.
Expand Down

0 comments on commit a3588e8

Please sign in to comment.