`-Wmaybe-uninitialized` when compiling with `-O1` #1361

issue hebasto opened this issue on June 27, 2023
  1. hebasto commented at 11:29 AM on June 27, 2023: member
    $ ./autogen.sh && ./configure CFLAGS=-O1
    $ make clean > /dev/null && make > /dev/null 
    In file included from src/secp256k1.c:30:
    In function 'secp256k1_ecmult_strauss_wnaf',
        inlined from 'secp256k1_ecmult' at src/ecmult_impl.h:353:5:
    src/ecmult_impl.h:291:5: warning: 'aux' may be used uninitialized [-Wmaybe-uninitialized]
      291 |     secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux);
          |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from src/secp256k1.c:29:
    src/group_impl.h: In function 'secp256k1_ecmult':
    src/group_impl.h:224:13: note: by argument 3 of type 'const secp256k1_fe *' to 'secp256k1_ge_table_set_globalz' declared here
      224 | static void secp256k1_ge_table_set_globalz(size_t len, secp256k1_ge *a, const secp256k1_fe *zr) {
          |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    src/ecmult_impl.h:345:18: note: 'aux' declared here
      345 |     secp256k1_fe aux[ECMULT_TABLE_SIZE(WINDOW_A)];
          |                  ^~~
    In file included from src/secp256k1.c:30,
                     from src/bench_internal.c:8:
    In function ‘secp256k1_ecmult_strauss_wnaf’,
        inlined from ‘secp256k1_ecmult’ at src/ecmult_impl.h:353:5:
    src/ecmult_impl.h:291:5: warning: ‘aux’ may be used uninitialized [-Wmaybe-uninitialized]
      291 |     secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux);
          |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from src/secp256k1.c:29:
    src/group_impl.h: In function ‘secp256k1_ecmult’:
    src/group_impl.h:224:13: note: by argument 3 of type ‘const secp256k1_fe *’ to ‘secp256k1_ge_table_set_globalz’ declared here
      224 | static void secp256k1_ge_table_set_globalz(size_t len, secp256k1_ge *a, const secp256k1_fe *zr) {
          |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    src/ecmult_impl.h:345:18: note: ‘aux’ declared here
      345 |     secp256k1_fe aux[ECMULT_TABLE_SIZE(WINDOW_A)];
          |                  ^~~
    

    Using gcc 12.2.

    No warnings with clang 15.

  2. real-or-random commented at 12:52 PM on June 27, 2023: contributor

    Wrapping the call in if (no > 0) suppresses this:

        if (no > 0) {
            secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux);
        }
    

    (Or adding SECP256K1_INLINE to secp256k1_ge_table_set_globalz, but this seems a bit arbitrary...)

  3. hebasto commented at 1:10 PM on June 27, 2023: member

    Wrapping the call in if (no > 0) suppresses this:

        if (no > 0) {
            secp256k1_ge_table_set_globalz(ECMULT_TABLE_SIZE(WINDOW_A) * no, state->pre_a, state->aux);
        }
    

    Would if (no) be more consistent with the code in for loop above?

  4. real-or-random commented at 2:27 PM on June 27, 2023: contributor

    Would if (no) be more consistent with the code in for loop above?

    I think so.

  5. hebasto cross-referenced this on Jun 28, 2023 from issue Avoid `-Wmaybe-uninitialized` when compiling with `gcc -O1` by hebasto
  6. real-or-random closed this on Jul 3, 2023


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 11:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me