Skip to content

Commit

Permalink
Merge pull request #42 from OJFord/fix-41
Browse files Browse the repository at this point in the history
Fix bad array subscript when sink disconnects
  • Loading branch information
Mario authored Nov 11, 2020
2 parents 28a2dcc + c063446 commit a0ff7bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pulseaudio-control.bash
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ function getNickname() {
getSinkName "$1"
unset SINK_NICKNAME

if [ -n "${SINK_NICKNAMES[$sinkName]}" ]; then
if [ -n "$sinkName" ] && [ -n "${SINK_NICKNAMES[$sinkName]}" ]; then
SINK_NICKNAME="${SINK_NICKNAMES[$sinkName]}"
elif [ -n "$SINK_NICKNAMES_PROP" ]; then
elif [ -n "$sinkName" ] && [ -n "$SINK_NICKNAMES_PROP" ]; then
getNicknameFromProp "$SINK_NICKNAMES_PROP" "$sinkName"
# Cache that result for next time
SINK_NICKNAMES["$sinkName"]="$SINK_NICKNAME"
Expand Down
9 changes: 9 additions & 0 deletions tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,13 @@ function setup() {
getNickname "$((i + offset))"
[ "$SINK_NICKNAME" = "Sink #$((i + offset))" ]
done

# Testing empty $sinkName.
# Observed to happen when a sink is removed (e.g. Bluetooth disconnect)
# possibly only with unlucky timing of when `getSinkName` runs. cf. #41
function getSinkName() {
sinkName=''
}
getNickname "$((10 + offset))" # beyond what exists
[ "$SINK_NICKNAME" = "Sink #$((10 + offset))" ]
}

0 comments on commit a0ff7bd

Please sign in to comment.