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

SC2038 seems to be triggered even when suggested form is used #3149

Open
srcshelton opened this issue Feb 17, 2025 · 0 comments
Open

SC2038 seems to be triggered even when suggested form is used #3149

srcshelton opened this issue Feb 17, 2025 · 0 comments

Comments

@srcshelton
Copy link

Version: v0.10.0-68-gd3001f3

Result from shellcheck:

In /mnt/generate-Kconfig.sh line 94:
  find "${repodir}/" \
  ^-- SC2038 (warning): Use 'find .. -print0 | xargs -0 ..' or 'find .. -exec .. +' to allow non-alphanumeric filenames.

Code:

 93             for dir in $( # <- Syntax
 94                     find "${repodir}/" \
 95                             -mindepth 3 \
 96                             -maxdepth 3 \
 97                             -name '*.ebuild' \
 98                             -type f \
 99                             -exec \
100                                 grep -Fl -- 'CONFIG_CHECK' {} + |
101                         xargs -rn 1 dirname |
102                         sort |
103                         uniq 
104                 )
105             do
    ...

The code already appears to be expressed in the second form suggested: find .. -exec .. + - I suspect that the line-continuation characters are throwing off this check?

(Admittedly, any update to the invocation of the find command above to correctly handle less-usual filenames would then be broken again by the for-loop, but that's not what SC2038 is talking about - really, the advice should be to refactor the code to something along the lines of:

  while read -r dir; dodone < <(
    find "${repodir}/" \
        … \
        -exec \
          grep -FZl -- 'CONFIG_CHECK' {} + |
      xargs -0rn 1 dirname  |
      sort  |
      uniq
  )

… which I think works? Either way, it begs the question of whether shellcheck could try to more explicitly identify cases of unsafe non-alphanumeric filename handling beyond cases of word-splitting currently reported - likely a whole can of worms 😯)

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

No branches or pull requests

1 participant