File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -243,16 +243,29 @@ func (h *Hardware) add(device hwinfo.HardwareDevice) error {
243
243
244
244
// We insert by physical id, as we only want one entry per core.
245
245
requiredSize := int (cpu .PhysicalID ) + 1 //nolint:gosec
246
+
246
247
if len (h .CPU ) < requiredSize {
247
248
newItems := make ([]* hwinfo.DetailCPU , requiredSize - len (h .CPU ))
248
249
h .CPU = append (h .CPU , newItems ... )
249
250
}
250
251
252
+ // add our new entry
251
253
h .CPU [cpu .PhysicalID ] = cpu
252
254
253
- // Sort in ascending order to ensure a stable output
255
+ // Sort in ascending order to ensure a stable output.
256
+ // It's possible that the CPU list contains nil pointers as we are not guaranteed to read the CPU's in order of
257
+ // physical id.
254
258
slices .SortFunc (h .CPU , func (a , b * hwinfo.DetailCPU ) int {
255
- return int (a .PhysicalID - b .PhysicalID ) //nolint:gosec
259
+ switch {
260
+ case a == nil && b == nil :
261
+ return 0
262
+ case a == nil && b != nil :
263
+ return - 1
264
+ case a != nil && b == nil :
265
+ return 1
266
+ default :
267
+ return int (a .PhysicalID - b .PhysicalID ) //nolint:gosec
268
+ }
256
269
})
257
270
258
271
case hwinfo .HardwareClassDisk :
You can’t perform that action at this time.
0 commit comments