Skip to content

Commit

Permalink
[secp256k1] initialize variable in tests
Browse files Browse the repository at this point in the history
Summary:
> This was detected while running the tests with the `-Wconditional-uninitialized` flag
>
> ```
> ./autogen.sh
> CC=clang CFLAGS="-Wconditional-uninitialized" ./configure
> make check
> ```
>
> The resulting warning is a false positive, but setting the value to -1
> ensures that the CHECK below will fail if recid is never written to.

This is a backport of [[bitcoin-core/secp256k1#889 | secp256k1#889]]

It should allow us to finally land D9110

Test Plan:
To check that this diff does not break existing tests:
`ninja && ninja check-secp256k1`

To check that this removes the compilation warning: rebased D9110 on top of this

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9372
  • Loading branch information
PiRK committed Apr 8, 2021
1 parent da7fa24 commit b0d8c60
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/secp256k1/src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -4372,8 +4372,10 @@ void test_ecdsa_sign_verify(void) {
secp256k1_scalar one;
secp256k1_scalar msg, key;
secp256k1_scalar sigr, sigs;
int recid;
int getrec;
/* Initialize recid to suppress a false positive -Wconditional-uninitialized in clang.
VG_UNDEF ensures that valgrind will still treat the variable as uninitialized. */
int recid = -1; VG_UNDEF(&recid, sizeof(recid));
random_scalar_order_test(&msg);
random_scalar_order_test(&key);
secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &pubj, &key);
Expand Down

0 comments on commit b0d8c60

Please sign in to comment.