Commit b010593
committed
core: Fix latent @go.printf infinite loop bug
Noticed the bug when trying to run:
time COLUMNS=27 ./go help builtins
The script would loop infinitely when trying to print the line for the
`path` builtin. When the `@go.printf` loop would reach the point where
the `prefix` variable contained:
'script, [alias] or'
the expression:
line="${line#$prefix}"
would cause `[alias]` to be interpreted as a set of characters to match
per standard Bash pattern matching, rather than as a literal string in
its own right. Consequently, the prefix would not get removed from
`line`, so `line` would remain constant and the loop condition
`"${#line}" -gt "$COLUMNS"` would never fail.
The fix was to use index notation and the length of `prefix` to trim
`line` instead:
line="${line:${#prefix}}"
The included test case reproduces the bug and verifies its fix.1 parent e033875 commit b010593
2 files changed
+18
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
170 | 172 | | |
171 | 173 | | |
172 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
0 commit comments