Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"bad array subscript" error #2455

Closed
sanjioh opened this issue Oct 19, 2024 · 4 comments · Fixed by #2461
Closed

"bad array subscript" error #2455

sanjioh opened this issue Oct 19, 2024 · 4 comments · Fixed by #2461
Labels

Comments

@sanjioh
Copy link

sanjioh commented Oct 19, 2024

Steps to reproduce the behavior

rbenv install 2.7.8

Expected vs. actual behavior

I get the error /usr/local/bin/ruby-build: line 1158: versions: bad array subscript, right after issuing the command, which I suppose should not happen.
The error is not blocking (build completes successfully).

Logs

$ ruby-build --version
ruby-build 20241017

This happens on an Intel Mac with macOS 14.7, ruby-build installed from Homebrew.

@sanjioh sanjioh added the bug label Oct 19, 2024
@mislav
Copy link
Member

mislav commented Oct 24, 2024

Thank you for reporting. This is strange, and I'm glad the error is at least non-fatal.

If you paste the following code into a bash shell, what does it output? (You could paste it into zsh too; it will likely work.)

  brew list 2>/dev/null | grep '^openssl@' | while read -r formula; do
    prefix="$(brew --prefix "$formula" 2>/dev/null || true)"
    [ -n "$prefix" ] || continue
    version="$("$prefix"/bin/openssl version 2>/dev/null | sed -n 's/OpenSSL \([0-9][0-9.]*\).*/\1/p')"
    [ -z "$version" ] || printf '%s %s %s\n' "$formula" "$version" "$prefix"
  done

@sanjioh
Copy link
Author

sanjioh commented Oct 25, 2024

Hi, thanks for replying.

The output is:

openssl@3 3.3.2 /usr/local/opt/openssl@3

@mislav
Copy link
Member

mislav commented Oct 28, 2024

Thanks for checking. That looks okay, so I actually don't know what triggers the "bad array subscript" error. However, I do think that ruby-build is trying to access an array at index -1 somehow, so I could add a guard around that, even if I don't understand how that index happened to be.

ruby-build/bin/ruby-build

Lines 1155 to 1158 in 572dd65

versions=( $(awk '{print $2}' <<<"$brew_installs" | sort_versions) )
local index="${#versions[@]}"
while [ $((index--)) -ge 0 ]; do
homebrew_version="$(normalize_semver "${versions[index]}")"

@mislav
Copy link
Member

mislav commented Nov 5, 2024

Another "bad array subscript" error spotted in the wild: #2387 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants