Commit 5f460da
committed
mountinfo: GetMountsFromReader() remove redundant switch, fix dropped fields
This switch was implementing the exact same check as is done in
strings.Join(); https://cs.opensource.google/go/go/+/refs/tags/go1.16.7:src/strings/strings.go;l=421-427
This only difference removing this switch makes is that it will assign
an empty string to p.Optional if no optional fields are present, but
given that an empty string is the default value for p.Optional, this
should make no difference.
This also revealed an off-by-one bug:
Before this change:
- we return an error if `sepIdx == 5` (earlier check)
- for `sepIdx == 6` we skipped (in this switch)
- for `7`, we take field 6 (equivalent to `fields[6:7]`, or `fields[6:sepIdx]`)
- for the "default" (else), we use `fields[6:sepIdx-1]`, which for (e.g.) `sepIndex=8`
would do the same as `sepIdx=7`, so we'd drop one value.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>1 parent f494bef commit 5f460da
2 files changed
+3
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
| 108 | + | |
116 | 109 | | |
117 | | - | |
| 110 | + | |
118 | 111 | | |
119 | 112 | | |
120 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
655 | 655 | | |
656 | 656 | | |
657 | 657 | | |
658 | | - | |
| 658 | + | |
659 | 659 | | |
660 | 660 | | |
661 | 661 | | |
| |||
0 commit comments