Skip to content

Commit cc0b279

Browse files
Eliminate a wrong -Wmaybe-uninitialized warning in GCC
1 parent 91b6477 commit cc0b279

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/modules/rangeproof/main_impl.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,15 @@ int secp256k1_pedersen_blind_generator_blind_sum(const secp256k1_context* ctx, c
182182
}
183183

184184
secp256k1_scalar_set_int(&sum, 0);
185-
for (i = 0; i < n_total; i++) {
185+
186+
/* Here, n_total > 0. Thus the loop runs at least once.
187+
Thus we may use a do-while loop, which checks the loop
188+
condition only at the end.
189+
190+
The do-while loop helps GCC prove that the loop runs at least
191+
once and suppresses a -Wmaybe-uninitialized warning. */
192+
i = 0;
193+
do {
186194
int overflow = 0;
187195
secp256k1_scalar addend;
188196
secp256k1_scalar_set_u64(&addend, value[i]); /* s = v */
@@ -207,7 +215,9 @@ int secp256k1_pedersen_blind_generator_blind_sum(const secp256k1_context* ctx, c
207215
secp256k1_scalar_cond_negate(&addend, i < n_inputs); /* s is negated if it's an input */
208216
secp256k1_scalar_add(&sum, &sum, &addend); /* sum += s */
209217
secp256k1_scalar_clear(&addend);
210-
}
218+
219+
i++;
220+
} while (i < n_total);
211221

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

0 commit comments

Comments
 (0)