Skip to content

Commit b07c304

Browse files
committed
refactor: Make 64-bit shift explicit
In addition, this change enables MSVC warning C4334 for the entire codebase. See: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4334 Required to enable level 3 warnings.
1 parent b2e29e4 commit b07c304

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ include(TryAppendCFlags)
207207
if(MSVC)
208208
# Keep the following commands ordered lexicographically.
209209
try_append_c_flags(/W2) # Moderate warning level.
210+
try_append_c_flags(/w24334) # Enable warning C4334 "result of 32-bit shift implicitly converted to 64 bits" as a level 2 one.
210211
try_append_c_flags(/wd4146) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned".
211212
else()
212213
# Keep the following commands ordered lexicographically.

configure.ac

+3-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ AC_DEFUN([SECP_TRY_APPEND_DEFAULT_CFLAGS], [
121121
# libtool makes the same assumption internally.
122122
# Note that "/opt" and "-opt" are equivalent for MSVC; we use "-opt" because "/opt" looks like a path.
123123
if test x"$GCC" != x"yes" && test x"$build_windows" = x"yes"; then
124-
SECP_TRY_APPEND_CFLAGS([-W2 -wd4146], $1) # Moderate warning level, disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned"
124+
SECP_TRY_APPEND_CFLAGS([-W2], $1) # Moderate warning level.
125+
SECP_TRY_APPEND_CFLAGS([-w24334], $1) # Enable warning C4334 "result of 32-bit shift implicitly converted to 64 bits" as a level 2 one.
126+
SECP_TRY_APPEND_CFLAGS([-wd4146], $1) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned".
125127
# We pass -ignore:4217 to the MSVC linker to suppress warning 4217 when
126128
# importing variables from a statically linked secp256k1.
127129
# (See the libtool manual, section "Windows DLLs" for background.)

src/ecmult_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ static int secp256k1_ecmult_pippenger_batch(const secp256k1_callback* error_call
683683
}
684684
state_space->ps = (struct secp256k1_pippenger_point_state *) secp256k1_scratch_alloc(error_callback, scratch, entries * sizeof(*state_space->ps));
685685
state_space->wnaf_na = (int *) secp256k1_scratch_alloc(error_callback, scratch, entries*(WNAF_SIZE(bucket_window+1)) * sizeof(int));
686-
buckets = (secp256k1_gej *) secp256k1_scratch_alloc(error_callback, scratch, (1<<bucket_window) * sizeof(*buckets));
686+
buckets = (secp256k1_gej *) secp256k1_scratch_alloc(error_callback, scratch, (1ULL << bucket_window) * sizeof(*buckets));
687687
if (state_space->ps == NULL || state_space->wnaf_na == NULL || buckets == NULL) {
688688
secp256k1_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint);
689689
return 0;

src/tests.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,7 @@ static void scalar_test(void) {
22212221
for (i = 0; i < 100; ++i) {
22222222
int low;
22232223
int shift = 1 + secp256k1_testrand_int(15);
2224-
int expected = r.d[0] % (1 << shift);
2224+
int expected = r.d[0] % (1ULL << shift);
22252225
low = secp256k1_scalar_shr_int(&r, shift);
22262226
CHECK(expected == low);
22272227
}

0 commit comments

Comments
 (0)