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

declaration shadows a local variable, in utf8.c #49

Open
snej opened this issue Feb 10, 2021 · 0 comments
Open

declaration shadows a local variable, in utf8.c #49

snej opened this issue Feb 10, 2021 · 0 comments

Comments

@snej
Copy link

snej commented Feb 10, 2021

There's a shadowed local variable in the function linenoiseUtf8NextCharLen. I build with -Wshadow and -Werror, so this warning breaks my build.

Behavior

Building with Clang ("Apple clang version 12.0.0") and -Wshadow produces:

linenoise-mob/utf8.c:468:13: error: declaration shadows a local variable [-Werror,-Wshadow]
        int cp;
            ^
linenoise-mob/utf8.c:459:9: note: previous declaration is here
    int cp;
        ^

Suggested Fix

Delete the duplicate int cp declaration, line 468: the existing cp in the outer scope isn't used again, so there's no harm in reusing it. Either that or rename the second cp to something unique.

(Apologies for not submitting a PR, but it didn't seem worth it to fork the entire repo just to submit a trivial 1-liner.)

Workaround

Update makefile / project to disable -Wshadow for this source file ... but it'd be better if the problem were fixed, since variable shadowing is kind of a footgun.

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