Xenapi-Admin-Project/xenapi-admin-tools — pull request #1 by erictjorg (2014-06-13 21:06:52+00:00)
Title: Infinite loop fix in yesno(), Unused var in getcolwidth()

Diff reasoning:

80: getcolwidth(): unused var cleanup
i=0 but was not using $i in the function.
It's only called within subshells (to grab its echo) that discard its $i

Replicate:
i=10; echo $i # 10
w=$(getcolwidth test); echo $w $i # 4 10
getcolwidth "test" # 4
echo $i # 0

With Fix:
i=10; echo $i # 10
w=$(getcolwidth test); echo $w $i # 4 10
getcolwidth "test" # 4
echo $i # 10

Shouldn't break anything extant, but avoids the reset if ever called directly

162-168: yesno(): infinite loop resolution
162: Unchanged, but any reason for echo;read vs read -p? (compatibility?)
166: Lining up ;; as done before
167: Lining up ;; as done before
168: *) case resulted in an infinite loop when not doing another read.
Just a read, or with prompt? "It depends", but others aren't using it.
Used the same echo;read pairing in case there's a compatibility reason.

Replicate:
yesno test # test? _
q # Invalid input
# Invalid input (loop until ^c)

With Fix:
yesno test # test? _
q # Invalid; test? _
y # (normal return, no loop)

Shouldn't break anything extant (nothing using it), but avoids the loop in case yesno() is called later.