Skip to content

Commit 985c0bd

Browse files
committed
Fixed nil pointer ref for comparison
1 parent 68446c6 commit 985c0bd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

internal/cmd/network-interface/list/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func outputProjectResult(p *print.Printer, outputFormat string, nics []iaas.NIC,
187187
}
188188

189189
slices.SortFunc(nics, func(a, b iaas.NIC) int {
190-
return cmp.Compare(*a.NetworkId, *b.NetworkId)
190+
return cmp.Compare(utils.PtrValue(a.NetworkId), utils.PtrValue(b.NetworkId))
191191
})
192192

193193
table := tables.NewTable()

internal/cmd/network-interface/list/list_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ func TestOutputProjectResult(t *testing.T) {
246246
},
247247
wantErr: false,
248248
},
249+
{
250+
name: "two empty NICs in NIC-slice to verify sorting by network id does not break on nil pointers",
251+
args: args{
252+
outputFormat: print.PrettyOutputFormat,
253+
nics: []iaas.NIC{{}, {}},
254+
},
255+
wantErr: false,
256+
},
249257
}
250258
p := print.NewPrinter()
251259
p.Cmd = NewCmd(&types.CmdParams{Printer: p})

0 commit comments

Comments
 (0)