Skip to content

Commit 5df77a0

Browse files
committed
Merge #533: Make sure we're not using an uninitialized variable in secp256k1_wnaf_const(...)
248f046 Make sure we're not using an uninitialized variable in secp256k1_wnaf_const(...) (practicalswift) Pull request description: Make sure we're not using an uninitialized variable in `secp256k1_wnaf_const(...)`: ``` In file included from src/secp256k1.c:15:0, from src/tests.c:17: src/ecmult_const_impl.h: In function ‘secp256k1_wnaf_const’: src/ecmult_const_impl.h:117:20: warning: ‘u’ may be used uninitialized in this function [-Wmaybe-uninitialized] wnaf[word] = u * global_sign; ^ ``` **Note to reviewers:** Perhaps an `assert(…);` is a bit drastic. What would be a more graceful way to handle this? :-) Tree-SHA512: 536cd7cc5b87a84fbaac578cecbba81b8d82e4672a30a2db9a674b82856132e79b0158a6a88609bc24942ebdbf1fcd2c4399a4c31ab0654b88ace9c0e6f1eaf3
2 parents 975e51e + 248f046 commit 5df77a0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/ecmult_const_impl.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ static int secp256k1_wnaf_const(int *wnaf, const secp256k1_scalar *scalar, int w
6161
int bit;
6262
secp256k1_scalar s;
6363
int not_neg_one;
64+
65+
VERIFY_CHECK(w > 0);
66+
VERIFY_CHECK(size > 0);
67+
6468
/* Note that we cannot handle even numbers by negating them to be odd, as is
6569
* done in other implementations, since if our scalars were specified to have
6670
* width < 256 for performance reasons, their negations would have width 256
@@ -94,7 +98,7 @@ static int secp256k1_wnaf_const(int *wnaf, const secp256k1_scalar *scalar, int w
9498

9599
/* 4 */
96100
u_last = secp256k1_scalar_shr_int(&s, w);
97-
while (word * w < size) {
101+
do {
98102
int sign;
99103
int even;
100104

@@ -110,7 +114,7 @@ static int secp256k1_wnaf_const(int *wnaf, const secp256k1_scalar *scalar, int w
110114
wnaf[word++] = u_last * global_sign;
111115

112116
u_last = u;
113-
}
117+
} while (word * w < size);
114118
wnaf[word] = u * global_sign;
115119

116120
VERIFY_CHECK(secp256k1_scalar_is_zero(&s));

0 commit comments

Comments
 (0)