mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
move error check out of the for loop
The `bufio.Scanner.Scan` method returns false either by reaching the end of the input or an error. After Scan returns false, the Err method will return any error that occurred during scanning, except that if it was io.EOF, Err will return nil. We should check the error when Scan return false(out of the for loop). Signed-off-by: Wang Long <long.wanglong@huawei.com>
This commit is contained in:
@@ -212,10 +212,6 @@ func parseStatusFile(path string) (map[string]string, error) {
|
||||
status := make(map[string]string)
|
||||
|
||||
for s.Scan() {
|
||||
if err := s.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
text := s.Text()
|
||||
parts := strings.Split(text, ":")
|
||||
|
||||
@@ -225,5 +221,9 @@ func parseStatusFile(path string) (map[string]string, error) {
|
||||
|
||||
status[parts[0]] = parts[1]
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return status, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user