Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing nil check for GetOrderedMap accessors #918

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading