Skip to content

enable -Wconversion and -Wsign-conversion by default #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ matrix:
# GCC for the x86-64 architecture with restricted limb sizes
# formerly started with the option "--with-low-mp" to testme.sh
# but testing all three in one run took to long and timed out.
- env: BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_8BIT --with-valgrind'
- env: BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_16BIT --with-valgrind'
- env: BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_32BIT --with-valgrind'
- env: NO_CONV_WARNINGS=1 BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_8BIT --with-valgrind'
- env: NO_CONV_WARNINGS=1 BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_16BIT --with-valgrind'
- env: NO_CONV_WARNINGS=1 BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_32BIT --with-valgrind'

# clang for the x86-64 architecture with restricted limb sizes
- env: BUILDOPTIONS='--with-cc=clang --cflags=-DMP_8BIT --with-valgrind'
- env: BUILDOPTIONS='--with-cc=clang --cflags=-DMP_16BIT --with-valgrind'
- env: BUILDOPTIONS='--with-cc=clang --cflags=-DMP_32BIT --with-valgrind'
- env: NO_CONV_WARNINGS=1 BUILDOPTIONS='--with-cc=clang --cflags=-DMP_8BIT --with-valgrind'
- env: NO_CONV_WARNINGS=1 BUILDOPTIONS='--with-cc=clang --cflags=-DMP_16BIT --with-valgrind'
- env: NO_CONV_WARNINGS=1 BUILDOPTIONS='--with-cc=clang --cflags=-DMP_32BIT --with-valgrind'

# GCC for the x86-64 architecture testing against a different Bigint-implementation
# with 333333 different inputs.
Expand Down
20 changes: 10 additions & 10 deletions demo/opponent.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int mtest_opponent(void)
FGETS(buf, 4095, stdin);
mp_read_radix(&b, buf, 64);

mp_mul_2d(&a, rr, &a);
mp_mul_2d(&a, (int)rr, &a);
a.sign = b.sign;
if (mp_cmp(&a, &b) != MP_EQ) {
printf("mul2d failed, rr == %u\n", rr);
Expand All @@ -96,7 +96,7 @@ int mtest_opponent(void)
FGETS(buf, 4095, stdin);
mp_read_radix(&b, buf, 64);

mp_div_2d(&a, rr, &a, &e);
mp_div_2d(&a, (int)rr, &a, &e);
a.sign = b.sign;
if ((a.used == b.used) && (a.used == 0)) {
a.sign = b.sign = MP_ZPOS;
Expand Down Expand Up @@ -128,10 +128,10 @@ int mtest_opponent(void)

/* test the sign/unsigned storage functions */

rr = mp_signed_bin_size(&c);
rr = (unsigned)mp_signed_bin_size(&c);
mp_to_signed_bin(&c, (unsigned char *) cmd);
memset(cmd + rr, rand() & 0xFFu, sizeof(cmd) - rr);
mp_read_signed_bin(&d, (unsigned char *) cmd, rr);
memset(cmd + rr, rand() & 0xFF, sizeof(cmd) - rr);
mp_read_signed_bin(&d, (unsigned char *) cmd, (int)rr);
if (mp_cmp(&c, &d) != MP_EQ) {
printf("mp_signed_bin failure!\n");
draw(&c);
Expand All @@ -140,10 +140,10 @@ int mtest_opponent(void)
}


rr = mp_unsigned_bin_size(&c);
rr = (unsigned)mp_unsigned_bin_size(&c);
mp_to_unsigned_bin(&c, (unsigned char *) cmd);
memset(cmd + rr, rand() & 0xFFu, sizeof(cmd) - rr);
mp_read_unsigned_bin(&d, (unsigned char *) cmd, rr);
memset(cmd + rr, rand() & 0xFF, sizeof(cmd) - rr);
mp_read_unsigned_bin(&d, (unsigned char *) cmd, (int)rr);
if (mp_cmp_mag(&c, &d) != MP_EQ) {
printf("mp_unsigned_bin failure!\n");
draw(&c);
Expand Down Expand Up @@ -343,7 +343,7 @@ int mtest_opponent(void)
sscanf(buf, "%d", &ix);
FGETS(buf, 4095, stdin);
mp_read_radix(&b, buf, 64);
mp_add_d(&a, ix, &c);
mp_add_d(&a, (mp_digit)ix, &c);
if (mp_cmp(&b, &c) != MP_EQ) {
printf("add_d %lu failure\n", add_d_n);
draw(&a);
Expand All @@ -360,7 +360,7 @@ int mtest_opponent(void)
sscanf(buf, "%d", &ix);
FGETS(buf, 4095, stdin);
mp_read_radix(&b, buf, 64);
mp_sub_d(&a, ix, &c);
mp_sub_d(&a, (mp_digit)ix, &c);
if (mp_cmp(&b, &c) != MP_EQ) {
printf("sub_d %lu failure\n", sub_d_n);
draw(&a);
Expand Down
43 changes: 22 additions & 21 deletions demo/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static int test_mp_jacobi(void)
mp_set_int(&b, jacobi[cnt].n);
/* only test positive values of a */
for (n = -5; n <= 10; ++n) {
mp_set_int(&a, abs(n));
mp_set_int(&a, (unsigned int)abs(n));
should = MP_OKAY;
if (n < 0) {
mp_neg(&a, &a);
Expand Down Expand Up @@ -221,14 +221,14 @@ static int test_mp_complement(void)
}

for (i = 0; i < 1000; ++i) {
int l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
mp_set_int(&a, labs(l));
long l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
mp_set_long(&a, (unsigned long)labs(l));
if (l < 0)
mp_neg(&a, &a);
mp_complement(&a, &b);

l = ~l;
mp_set_int(&c, labs(l));
mp_set_long(&c, (unsigned long)labs(l));
if (l < 0)
mp_neg(&c, &c);

Expand All @@ -255,16 +255,17 @@ static int test_mp_tc_div_2d(void)
}

for (i = 0; i < 1000; ++i) {
int l, em;
long l;
int em;

l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
mp_set_int(&a, labs(l));
mp_set_long(&a, (unsigned long)labs(l));
if (l < 0)
mp_neg(&a, &a);

em = rand() % 32;

mp_set_int(&d, labs(l >> em));
mp_set_long(&d, (unsigned long)labs(l >> em));
if ((l >> em) < 0)
mp_neg(&d, &d);

Expand Down Expand Up @@ -296,16 +297,16 @@ static int test_mp_tc_xor(void)
int l, em;

l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
mp_set_int(&a, labs(l));
mp_set_int(&a, (unsigned long)labs(l));
if (l < 0)
mp_neg(&a, &a);

em = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
mp_set_int(&b, labs(em));
mp_set_int(&b, (unsigned long)labs(em));
if (em < 0)
mp_neg(&b, &b);

mp_set_int(&d, labs(l ^ em));
mp_set_int(&d, (unsigned long)labs(l ^ em));
if ((l ^ em) < 0)
mp_neg(&d, &d);

Expand Down Expand Up @@ -334,19 +335,19 @@ static int test_mp_tc_or(void)
}

for (i = 0; i < 1000; ++i) {
int l, em;
long l, em;

l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
mp_set_int(&a, labs(l));
mp_set_long(&a, (unsigned long)labs(l));
if (l < 0)
mp_neg(&a, &a);

em = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
mp_set_int(&b, labs(em));
mp_set_long(&b, (unsigned long)labs(em));
if (em < 0)
mp_neg(&b, &b);

mp_set_int(&d, labs(l | em));
mp_set_long(&d, (unsigned long)labs(l | em));
if ((l | em) < 0)
mp_neg(&d, &d);

Expand Down Expand Up @@ -374,19 +375,19 @@ static int test_mp_tc_and(void)
}

for (i = 0; i < 1000; ++i) {
int l, em;
long l, em;

l = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
mp_set_int(&a, labs(l));
mp_set_long(&a, (unsigned long)labs(l));
if (l < 0)
mp_neg(&a, &a);

em = (rand() * rand() + 1) * (rand() % 1 ? -1 : 1);
mp_set_int(&b, labs(em));
mp_set_long(&b, (unsigned long)labs(em));
if (em < 0)
mp_neg(&b, &b);

mp_set_int(&d, labs(l & em));
mp_set_long(&d, (unsigned long)labs(l & em));
if ((l & em) < 0)
mp_neg(&d, &d);

Expand Down Expand Up @@ -554,9 +555,9 @@ static int test_mp_get_long(void)
}

for (i = 0; i < ((int)(sizeof(unsigned long)*CHAR_BIT) - 1); ++i) {
t = (1ULL << (i+1)) - 1;
t = (1UL << (i+1)) - 1;
if (!t)
t = -1;
t = ~0UL;
printf(" t = 0x%lx i = %d\r", t, i);
do {
if (mp_set_long(&a, t) != MP_OKAY) {
Expand Down Expand Up @@ -592,7 +593,7 @@ static int test_mp_get_long_long(void)
for (i = 0; i < ((int)(sizeof(unsigned long long)*CHAR_BIT) - 1); ++i) {
r = (1ULL << (i+1)) - 1;
if (!r)
r = -1;
r = ~0ULL;
printf(" r = 0x%llx i = %d\r", r, i);
do {
if (mp_set_long_long(&a, r) != MP_OKAY) {
Expand Down
8 changes: 6 additions & 2 deletions makefile_include.mk
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow

ifndef NO_ADDTL_WARNINGS
# additional warnings
CFLAGS += -Wsystem-headers
CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
CFLAGS += -Wstrict-prototypes -Wpointer-arith
#CFLAGS += -Wconversion -Wsign-conversion
endif

ifdef NO_CONV_WARNINGS
CFLAGS += -Wsystem-headers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not keep them enabled by default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are conversion warnings in the system headers unfortunately. I also don't think Wsystem-headers is particularly useful since we cannot do anything about those issues. I never activate these warnings since they are only intended for people working on the system headers it seems.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But with NO_CONV_WARNINGS=1 for the 16 and 8 bit builds we also have the warnings activated at least sometimes in the CI, which is better than nothing :)

else
CFLAGS += -Wconversion -Wsign-conversion
endif

ifdef COMPILE_DEBUG
Expand Down
2 changes: 1 addition & 1 deletion mtest/logtab.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const float s_logv_2[] = {
const double s_logv_2[] = {
0.000000000, 0.000000000, 1.000000000, 0.630929754, /* 0 1 2 3 */
0.500000000, 0.430676558, 0.386852807, 0.356207187, /* 4 5 6 7 */
0.333333333, 0.315464877, 0.301029996, 0.289064826, /* 8 9 10 11 */
Expand Down
5 changes: 5 additions & 0 deletions mtest/mtest.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#if defined(__GNUC__) || defined(__clang__)
# pragma GCC diagnostic ignored "-Wconversion"
# pragma GCC diagnostic ignored "-Wsign-conversion"
#endif

/* makes a bignum test harness with NUM tests per operation
*
* the output is made in the following format [one parameter per line]
Expand Down