@@ -224,12 +224,16 @@ func updateSystemLoad(ret *model.SystemInfo) {
224224 out , err := exec .Command ("w" ).Output ()
225225 if err == nil {
226226 loadFields := strings .Fields (string (out ))
227- load = strings .Join (loadFields [len (loadFields )- 3 :], " " )
227+ if len (loadFields ) >= 3 {
228+ load = strings .Join (loadFields [len (loadFields )- 3 :], " " )
229+ }
228230 } else {
229231 out , err = exec .Command ("uptime" ).Output ()
230232 if err == nil {
231233 fields := strings .Fields (string (out ))
232- load = strings .Join (fields [len (fields )- 3 :], " " )
234+ if len (fields ) >= 3 {
235+ load = strings .Join (fields [len (fields )- 3 :], " " )
236+ }
233237 }
234238 }
235239 if load != "" {
@@ -619,13 +623,22 @@ func getDarwinCpuInfo(ret *model.SystemInfo) (*model.SystemInfo, error) {
619623 if len (model .MacOSInfo ) > 0 {
620624 for _ , line := range model .MacOSInfo {
621625 if strings .Contains (line , "Chip" ) && ret .CpuModel == "" {
622- ret .CpuModel = strings .TrimSpace (strings .Split (line , ":" )[1 ])
626+ parts := strings .SplitN (line , ":" , 2 )
627+ if len (parts ) == 2 {
628+ ret .CpuModel = strings .TrimSpace (parts [1 ])
629+ }
623630 }
624631 if strings .Contains (line , "Total Number of Cores" ) && ret .CpuCores == "" {
625- ret .CpuCores = strings .TrimSpace (strings .Split (line , ":" )[1 ])
632+ parts := strings .SplitN (line , ":" , 2 )
633+ if len (parts ) == 2 {
634+ ret .CpuCores = strings .TrimSpace (parts [1 ])
635+ }
626636 }
627637 if strings .Contains (line , "Memory" ) && ret .MemoryTotal == "" {
628- ret .MemoryTotal = strings .TrimSpace (strings .Split (line , ":" )[1 ])
638+ parts := strings .SplitN (line , ":" , 2 )
639+ if len (parts ) == 2 {
640+ ret .MemoryTotal = strings .TrimSpace (parts [1 ])
641+ }
629642 }
630643 }
631644 }
@@ -664,7 +677,10 @@ func updateSysctlCpuInfo(ret *model.SystemInfo, sysctlPath string) {
664677 if ret .CpuCache == "" {
665678 ccache , err := getSysctlValue (sysctlPath , "hw.cacheconfig" )
666679 if err == nil && ! strings .Contains (ccache , "cannot" ) {
667- ret .CpuCache = strings .TrimSpace (strings .Split (ccache , ":" )[1 ])
680+ parts := strings .Split (ccache , ":" )
681+ if len (parts ) > 1 {
682+ ret .CpuCache = strings .TrimSpace (parts [1 ])
683+ }
668684 }
669685 }
670686}
0 commit comments