bash-completion icon indicating copy to clipboard operation
bash-completion copied to clipboard

COMP_WORDS: bad array subscript

Open soliton- opened this issue 2 years ago • 3 comments

I get the error from the title with var= ./do<tab> ; when attempting tab completion at the indicated position.

https://github.com/scop/bash-completion/blob/f5756939a45e5da774274293768da2d7e547d8c4/bash_completion#L2276-L2280

"${COMP_WORDS[-1]}" is used in the else case even when COMP_WORDS is empty in which case index -1 is invalid.

soliton- avatar Jun 28 '22 12:06 soliton-

I can reproduce (just tested, no idea when I'll get around to looking into it more, anyone feel free). However, in the future, when filing issues, please fill the issue template completely to avoid unnecessary debugging work and comment roundtrips. Thanks in advance!

scop avatar Jun 28 '22 13:06 scop

I created the issue from the referenced code with "Reference in new issue". I got no template. There was only a link to the contributing guidelines which I read.

Regarding a fix, I guess the simplest would be to just add another case for ${#COMP_WORDS[@]} == 0 with $func "$cmd". At least it looks like a sensible thing to do given the existing code. Not that I have any idea what this is trying to accomplish.

soliton- avatar Jun 28 '22 18:06 soliton-

Oh, not presenting the template in that case is unfortunate of GitHub. Anyway FFR the template is https://raw.githubusercontent.com/scop/bash-completion/master/.github/ISSUE_TEMPLATE/bug_report.md

scop avatar Jun 29 '22 06:06 scop