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

refactor: Use && in boolean context to avoid compiler warning #1006

Closed
wants to merge 1 commit into from
Closed

Conversation

maflcko
Copy link
Contributor

@maflcko maflcko commented Nov 8, 2021

This fixes a compiler warning:

./src/ecdsa_impl.h:312:12: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]
    return !secp256k1_scalar_is_zero(sigr) & !secp256k1_scalar_is_zero(sigs);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                           &&

This fixes a compiler warning:

./src/ecdsa_impl.h:312:12: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]
    return !secp256k1_scalar_is_zero(sigr) & !secp256k1_scalar_is_zero(sigs);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                           &&
@maflcko
Copy link
Contributor Author

maflcko commented Nov 8, 2021

I didn't try to reproduce this, but I randomly saw it in logs on a 32-bit compilation with clang-14 (trunk) and some odd compiler flags like -O0.

@maflcko
Copy link
Contributor Author

maflcko commented Nov 8, 2021

Ah, I see.

Good thing there are tests.

@maflcko maflcko closed this Nov 8, 2021
@maflcko maflcko deleted the 2111-amp branch November 8, 2021 15:23
@sipa
Copy link
Contributor

sipa commented Nov 8, 2021

:)

@maflcko
Copy link
Contributor Author

maflcko commented Nov 8, 2021

This is in clang-14 (for now): llvm/llvm-project@f62d18f

@sipa
Copy link
Contributor

sipa commented Nov 8, 2021

If there is a need to silence anything, I think the correct approach is suggested there: cast one of the inputs to & to int.

real-or-random added a commit that referenced this pull request Nov 9, 2021
…mpiler warning

16d1322 refactor: Use (int)&(int) in boolean context to avoid compiler warning (MarcoFalke)

Pull request description:

  This one should *really* be only a refactor with the goal to silence static analysis warnings. clang-14 (trunk) recently added one in commit llvm/llvm-project@f62d18f and I expect other tools will offer similar warnings.

  Follow up to #1006, which was not a refactor.

ACKs for top commit:
  real-or-random:
    ACK 16d1322
  jonasnick:
    ACK 16d1322

Tree-SHA512: c465522ea4ddb58b5974c95bc36423c453e6fcf5948cb32114172113b5244209ceaa9418ec86ebe210390ae5509c2f24a42c41a7353de4cfb8fd063b0d5c0e79
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.

2 participants