Skip to content

Commit

Permalink
Merge #136: Eliminate a wrong -Wmaybe-uninitialized warning in GCC
Browse files Browse the repository at this point in the history
cc0b279 Eliminate a wrong -Wmaybe-uninitialized warning in GCC (Tim Ruffing)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK cc0b279

Tree-SHA512: ee9ae840ba7df471f566fc9b4d5bdf04e1d0759bd6fec1d1144e0e7b3f12603865371d238f8a2ee4648db88224e5ea582ab837c2cbc041d2582141736ebe5fd0
  • Loading branch information
jonasnick committed Jul 14, 2021
2 parents 6db00f5 + cc0b279 commit d9560e0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/modules/rangeproof/main_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,15 @@ int secp256k1_pedersen_blind_generator_blind_sum(const secp256k1_context* ctx, c
}

secp256k1_scalar_set_int(&sum, 0);
for (i = 0; i < n_total; i++) {

/* Here, n_total > 0. Thus the loop runs at least once.
Thus we may use a do-while loop, which checks the loop
condition only at the end.
The do-while loop helps GCC prove that the loop runs at least
once and suppresses a -Wmaybe-uninitialized warning. */
i = 0;
do {
int overflow = 0;
secp256k1_scalar addend;
secp256k1_scalar_set_u64(&addend, value[i]); /* s = v */
Expand All @@ -207,7 +215,9 @@ int secp256k1_pedersen_blind_generator_blind_sum(const secp256k1_context* ctx, c
secp256k1_scalar_cond_negate(&addend, i < n_inputs); /* s is negated if it's an input */
secp256k1_scalar_add(&sum, &sum, &addend); /* sum += s */
secp256k1_scalar_clear(&addend);
}

i++;
} while (i < n_total);

/* Right now tmp has the last pedersen blinding factor. Subtract the sum from it. */
secp256k1_scalar_negate(&sum, &sum);
Expand Down

0 comments on commit d9560e0

Please sign in to comment.