Skip to content

Commit a6effd3

Browse files
committed
parseCPUInfo*: add error checking
In case the input can't be read, scanner.Scan() stops and the code is supposed to check for error using scanner.Err(). Do that. In other words, instead of returning half-read cpuinfo, return an error. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent a175916 commit a6effd3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cpuinfo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func parseCPUInfoX86(info io.Reader) ([]CPUInfo, error) {
183183
cpuinfo[i].PowerManagement = field[1]
184184
}
185185
}
186-
return cpuinfo, nil
186+
return cpuinfo, scanner.Err()
187187
}
188188

189189
func parseCPUInfoARM(info io.Reader) ([]CPUInfo, error) {
@@ -233,7 +233,7 @@ func parseCPUInfoARM(info io.Reader) ([]CPUInfo, error) {
233233
}
234234
}
235235

236-
return cpuinfo, nil
236+
return cpuinfo, scanner.Err()
237237
}
238238

239239
func parseCPUInfoS390X(info io.Reader) ([]CPUInfo, error) {
@@ -301,7 +301,7 @@ func parseCPUInfoS390X(info io.Reader) ([]CPUInfo, error) {
301301
}
302302
}
303303

304-
return cpuinfo, nil
304+
return cpuinfo, scanner.Err()
305305
}
306306

307307
func parseCPUInfoPPC(info io.Reader) ([]CPUInfo, error) {
@@ -346,7 +346,7 @@ func parseCPUInfoPPC(info io.Reader) ([]CPUInfo, error) {
346346
cpuinfo[i].CPUMHz = v
347347
}
348348
}
349-
return cpuinfo, nil
349+
return cpuinfo, scanner.Err()
350350
}
351351

352352
// firstNonEmptyLine advances the scanner to the first non-empty line

0 commit comments

Comments
 (0)