Commit 99cfd57
committed
mountinfo: move s.Err() out of scanner loop
The previous code would actually ignore IO errors during scanning,
becuase s.Scan() returns false if there was an error (leaving the loop
and never being detected). Indeed the correct way[1] of using the
builtin bufio.Scanner is actually more like:
s := bufio.NewScanner(...)
for s.Scan() {
// use s.Text()
}
if err := s.Err(); err != nil {
return err
}
[1]: https://blog.golang.org/errors-are-values
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>1 parent 95f2efb commit 99cfd57
1 file changed
Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 22 | + | |
| 23 | + | |
26 | 24 | | |
27 | 25 | | |
28 | 26 | | |
| |||
133 | 131 | | |
134 | 132 | | |
135 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
| |||
0 commit comments