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

src/binutils-config: fix shellcheck warnings #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

akpall
Copy link
Contributor

@akpall akpall commented Jan 5, 2025

No description provided.

@thesamesam
Copy link
Member

Ideally the commit message body would include the warnings fixed.

"${EROOT}"/usr/libexec/gcc/${TARGET}/${x}
"${EROOT}"/usr/bin/"${TARGET}"-"${x}"
"${EROOT}"/usr/{${HOST}/,}"${TARGET}"/bin/"${x}"
"${EROOT}"/usr/libexec/gcc/"${TARGET}"/"${x}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eyebleed city :( if you're quoting nearly an entire string, don't stop quoting just for the staticky-ness of a literal forward slash.

@akpall akpall force-pushed the fix-shellcheck-warnings branch from 58f57d4 to e68cdb8 Compare January 19, 2025 16:17
@@ -281,7 +283,7 @@ switch_profile() {
#
# Regen env.d if need/can be
#
if [[ ${ROOT} == "/" ]] && [[ ${TARGET} == ${HOST} ]] ; then
if [[ ${ROOT} == "/" ]] && [[ ${TARGET} == "${HOST}" ]] ; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to touch the line, we should combine the conditionals.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We maybe don't really need to touch the line at all, since [[ explicitly defines variable quoting as unnecessary for the purpose of performing field splitting and filename expansion.

There is still a semantic difference -- a wildcard in ${HOST} will be treated as a wildcard-match (and other forms of pattern matching, including extglob) against the value of ${TARGET} -- but that could be called a feature. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to quote it due to ${HOST} being set to a string and if you want globbing, then it would be better to set it at RHS in test and not inside ${HOST}. Hopefully I understood you correctly.

EROOT="${ROOT%/}${EPREFIX}/"
export PORTAGE_CONFIGROOT="${EROOT}"

cd "${BROOT}/"
cd "${BROOT}/" || die "Could not cd into $BROOT"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gentoo style is:

Suggested change
cd "${BROOT}/" || die "Could not cd into $BROOT"
cd "${BROOT}/" || die "Could not cd into ${BROOT}"

Fixed warnings:
src/binutils-config:129:21: warning: Quote the right-hand side of != in [[ ]] to prevent glob matching. [SC2053]
[...]
src/binutils-config:179:22: warning: Quote the right-hand side of == in [[ ]] to prevent glob matching. [SC2053]
[...]
src/binutils-config:61:7: note: Double quote to prevent globbing and word splitting. [SC2086]
[...]
src/binutils-config:18:1: warning: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. [SC2164]
src/binutils-config:323:23: warning: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a. [SC2206]
[...]
src/binutils-config:9:3: note: This default assignment may cause DoS due to globbing. Quote it. [SC2223]
[...]
src/binutils-config:306:28: note: Quote expansions in this for loop glob to prevent wordsplitting, e.g. "$dir"/*.txt . [SC2231]

Disabled warnings:
src/binutils-config:24:8: warning: ShellCheck can't follow non-constant source. Use a directive to specify location. [SC1090]
[...]

Signed-off-by: Allen-Kristjan Päll <[email protected]>
@akpall akpall force-pushed the fix-shellcheck-warnings branch from e68cdb8 to e089c4b Compare January 19, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants