Skip to content

Commit 7478417

Browse files
authored
Merge branch 'develop' into deprecate-macros
2 parents 8a9ce10 + a6b5da2 commit 7478417

File tree

8 files changed

+126
-80
lines changed

8 files changed

+126
-80
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ libtommath.pc
7474
gcc_errors_*.txt
7575
test_*.txt
7676

77+
.#*
78+
*~
7779
*.bak
7880
*.orig
7981
*.asc

.travis.yml

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ branches:
3131
only:
3232
- master
3333
- develop
34-
- /^release\/.*$/
34+
- /^release/
35+
- /^travis/
3536

36-
# Additional installs are Valgrind for the memory-tests
37-
# and gcc-multilib for the compilation of the different
38-
# architectures.
37+
# Additional installs: Valgrind for memory tests.
3938
install:
4039
- sudo apt-get update -qq
4140
- sudo apt-get install valgrind
42-
- sudo apt-get install gcc-multilib
41+
- apt-cache search gcc | grep '^gcc-[0-9\.]* '
42+
- apt-cache search clang | grep compiler
4343

4444
# The language is C and it will load the respective dependencies
4545
language: c
@@ -66,60 +66,90 @@ matrix:
6666
apt:
6767
packages:
6868
- astyle
69-
sudo: required
7069

7170
# GCC for the 32-bit architecture (no valgrind yet)
72-
- env: BUILDOPTIONS='--with-cc=gcc --with-m32'
71+
- env: BUILDOPTIONS='--with-cc=gcc-5 --with-m32'
7372
addons:
7473
apt:
7574
packages:
7675
- libc6-dev-i386
77-
sudo: required
76+
- gcc-multilib
7877

7978
# clang for the 32-bit architecture (no valgrind yet)
80-
- env: BUILDOPTIONS='--with-cc=clang --with-m32'
79+
- env: BUILDOPTIONS='--with-cc=clang-7 --with-m32'
8180
addons:
8281
apt:
8382
packages:
8483
- libc6-dev-i386
85-
sudo: required
84+
- gcc-multilib
8685

8786
# GCC for the x64_32 architecture (32-bit longs and 32-bit pointers)
8887
# TODO: Probably not possible to run anything in x32 in Travis
8988
# but needs to be checked to be sure.
90-
- env: BUILDOPTIONS='--with-cc=gcc --with-mx32'
89+
- env: BUILDOPTIONS='--with-cc=gcc-5 --with-mx32'
9190
addons:
9291
apt:
9392
packages:
9493
- libc6-dev-x32
95-
sudo: required
94+
- gcc-multilib
9695

9796
# GCC for the x86-64 architecture (64-bit longs and 64-bit pointers)
98-
- env: BUILDOPTIONS='--with-cc=gcc --with-m64 --with-valgrind'
97+
- env: BUILDOPTIONS='--with-cc=gcc-5 --with-m64 --with-valgrind'
98+
- env: BUILDOPTIONS='--with-cc=gcc-4.7 --with-m64 --with-valgrind'
99+
addons:
100+
apt:
101+
packages:
102+
- gcc-4.7
103+
- env: BUILDOPTIONS='--with-cc=gcc-4.8 --with-m64 --with-valgrind'
104+
addons:
105+
apt:
106+
packages:
107+
- gcc-4.8
108+
- env: BUILDOPTIONS='--with-cc=gcc-4.9 --with-m64 --with-valgrind'
109+
addons:
110+
apt:
111+
packages:
112+
- gcc-4.9
113+
99114
# clang for x86-64 architecture (64-bit longs and 64-bit pointers)
100-
- env: BUILDOPTIONS='--with-cc=clang --with-m64 --with-valgrind'
115+
- env: CONV_WARNINGS=1 BUILDOPTIONS='--with-cc=clang-7 --with-m64 --with-valgrind'
116+
- env: BUILDOPTIONS='--with-cc=clang-6.0 --with-m64 --with-valgrind'
117+
addons:
118+
apt:
119+
packages:
120+
- clang-6.0
121+
- env: BUILDOPTIONS='--with-cc=clang-5.0 --with-m64 --with-valgrind'
122+
addons:
123+
apt:
124+
packages:
125+
- clang-5.0
126+
- env: BUILDOPTIONS='--with-cc=clang-4.0 --with-m64 --with-valgrind'
127+
addons:
128+
apt:
129+
packages:
130+
- clang-4.0
101131

102132
# GCC for the x86-64 architecture with restricted limb sizes
103133
# formerly started with the option "--with-low-mp" to testme.sh
104134
# but testing all three in one run took to long and timed out.
105-
- env: BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_8BIT --with-valgrind'
106-
- env: BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_16BIT --with-valgrind'
107-
- env: BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_32BIT --with-valgrind'
135+
- env: BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_8BIT --with-valgrind'
136+
- env: BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_16BIT --with-valgrind'
137+
- env: BUILDOPTIONS='--with-cc=gcc-5 --cflags=-DMP_32BIT --with-valgrind'
108138

109139
# clang for the x86-64 architecture with restricted limb sizes
110-
- env: BUILDOPTIONS='--with-cc=clang --cflags=-DMP_8BIT --with-valgrind'
111-
- env: BUILDOPTIONS='--with-cc=clang --cflags=-DMP_16BIT --with-valgrind'
112-
- env: BUILDOPTIONS='--with-cc=clang --cflags=-DMP_32BIT --with-valgrind'
140+
- env: BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_8BIT --with-valgrind'
141+
- env: BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_16BIT --with-valgrind'
142+
- env: BUILDOPTIONS='--with-cc=clang-7 --cflags=-DMP_32BIT --with-valgrind'
113143

114144
# GCC for the x86-64 architecture testing against a different Bigint-implementation
115145
# with 333333 different inputs.
116-
- env: BUILDOPTIONS='--with-cc=gcc --test-vs-mtest=333333 --with-valgrind'
117-
- env: BUILDOPTIONS='--with-cc=clang --test-vs-mtest=333333 --with-valgrind'
146+
- env: BUILDOPTIONS='--with-cc=gcc-5 --test-vs-mtest=333333 --with-valgrind'
147+
- env: BUILDOPTIONS='--with-cc=clang-7 --test-vs-mtest=333333 --with-valgrind'
118148

119149
# clang for the x86-64 architecture testing against a different Bigint-implementation
120150
# with a better random source.
121-
- env: BUILDOPTIONS='--with-cc=gcc --test-vs-mtest=333333 --mtest-real-rand --with-valgrind'
122-
- env: BUILDOPTIONS='--with-cc=clang --test-vs-mtest=333333 --mtest-real-rand --with-valgrind'
151+
- env: BUILDOPTIONS='--with-cc=gcc-5 --test-vs-mtest=333333 --mtest-real-rand --with-valgrind'
152+
- env: BUILDOPTIONS='--with-cc=clang-7 --test-vs-mtest=333333 --mtest-real-rand --with-valgrind'
123153

124154
# Notifications go to
125155
# An email address is also possible.
@@ -132,5 +162,4 @@ notifications:
132162
# seem to be the max and 20 the default if travis_wait is called without
133163
# any options.
134164
script:
135-
- ./testme.sh ${BUILDOPTIONS}
136-
165+
- ./testme.sh ${BUILDOPTIONS}

bn_mp_ilogb.c

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
static mp_word s_pow(mp_word base, mp_word exponent)
88
{
99
mp_word result = 1uLL;
10-
while (exponent) {
11-
if ((exponent & 0x1) == 1) {
10+
while (exponent != 0u) {
11+
if ((exponent & 1u) == 1u) {
1212
result *= base;
1313
}
1414
exponent >>= 1;
@@ -85,25 +85,29 @@ int mp_ilogb(mp_int *a, mp_digit base, mp_int *c)
8585
return MP_VAL;
8686
}
8787

88-
if (base < 2) {
88+
if (base < 2u) {
8989
return MP_VAL;
90-
} else if (base == 2) {
90+
}
91+
if (base == 2u) {
9192
cmp = mp_count_bits(a) - 1;
92-
mp_set_int(c, (unsigned long)cmp);
93+
if ((err = mp_set_int(c, (unsigned long)cmp)) != MP_OKAY) {
94+
goto LBL_ERR;
95+
}
9396
return err;
94-
} else if (a->used == 1) {
97+
}
98+
if (a->used == 1) {
9599
tmp = s_digit_ilogb(base, a->dp[0]);
96100
mp_set(c, tmp);
97101
return err;
98102
}
99103

100-
101104
cmp = mp_cmp_d(a, base);
102105

103106
if (cmp == MP_LT) {
104107
mp_zero(c);
105108
return err;
106-
} else if (cmp == MP_EQ) {
109+
}
110+
if (cmp == MP_EQ) {
107111
mp_set(c, (mp_digit)1uL);
108112
return err;
109113
}
@@ -114,9 +118,9 @@ int mp_ilogb(mp_int *a, mp_digit base, mp_int *c)
114118
return err;
115119
}
116120

117-
low = 0uL;
121+
low = 0u;
118122
mp_set(&bracket_low, 1uL);
119-
high = 1uL;
123+
high = 1u;
120124

121125
mp_set(&bracket_high, base);
122126

@@ -138,14 +142,14 @@ int mp_ilogb(mp_int *a, mp_digit base, mp_int *c)
138142
}
139143
mp_set(&bi_base, base);
140144

141-
while ((high - low) > 1) {
145+
while ((high - low) > 1u) {
142146
mid = (high + low) >> 1;
143147
/* Difference can be larger then the type behind mp_digit can hold */
144148
if ((mid - low) > (unsigned int)(MP_MASK)) {
145149
err = MP_VAL;
146150
goto LBL_ERR;
147151
}
148-
if ((err = mp_expt_d(&bi_base, (mid - low), &t)) != MP_OKAY) {
152+
if ((err = mp_expt_d(&bi_base, (mp_digit)(mid - low), &t)) != MP_OKAY) {
149153
goto LBL_ERR;
150154
}
151155
if ((err = mp_mul(&bracket_low, &t, &bracket_mid)) != MP_OKAY) {
@@ -161,15 +165,21 @@ int mp_ilogb(mp_int *a, mp_digit base, mp_int *c)
161165
mp_exch(&bracket_mid, &bracket_low);
162166
}
163167
if (cmp == MP_EQ) {
164-
mp_set_int(c, (unsigned long)mid);
168+
if ((err = mp_set_int(c, (unsigned long)mid)) != MP_OKAY) {
169+
goto LBL_ERR;
170+
}
165171
goto LBL_END;
166172
}
167173
}
168174

169175
if (mp_cmp(&bracket_high, a) == MP_EQ) {
170-
mp_set_int(c, (unsigned long)high);
176+
if ((err = mp_set_int(c, (unsigned long)high)) != MP_OKAY) {
177+
goto LBL_ERR;
178+
}
171179
} else {
172-
mp_set_int(c, (unsigned long)low);
180+
if ((err = mp_set_int(c, (unsigned long)low)) != MP_OKAY) {
181+
goto LBL_ERR;
182+
}
173183
}
174184

175185
LBL_END:

demo/opponent.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int mtest_opponent(void)
7979
FGETS(buf, 4095, stdin);
8080
mp_read_radix(&b, buf, 64);
8181

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

99-
mp_div_2d(&a, rr, &a, &e);
99+
mp_div_2d(&a, (int)rr, &a, &e);
100100
a.sign = b.sign;
101101
if ((a.used == b.used) && (a.used == 0)) {
102102
a.sign = b.sign = MP_ZPOS;
@@ -128,10 +128,10 @@ int mtest_opponent(void)
128128

129129
/* test the sign/unsigned storage functions */
130130

131-
rr = mp_signed_bin_size(&c);
131+
rr = (unsigned)mp_signed_bin_size(&c);
132132
mp_to_signed_bin(&c, (unsigned char *) cmd);
133-
memset(cmd + rr, rand() & 0xFFu, sizeof(cmd) - rr);
134-
mp_read_signed_bin(&d, (unsigned char *) cmd, rr);
133+
memset(cmd + rr, rand() & 0xFF, sizeof(cmd) - rr);
134+
mp_read_signed_bin(&d, (unsigned char *) cmd, (int)rr);
135135
if (mp_cmp(&c, &d) != MP_EQ) {
136136
printf("mp_signed_bin failure!\n");
137137
draw(&c);
@@ -140,10 +140,10 @@ int mtest_opponent(void)
140140
}
141141

142142

143-
rr = mp_unsigned_bin_size(&c);
143+
rr = (unsigned)mp_unsigned_bin_size(&c);
144144
mp_to_unsigned_bin(&c, (unsigned char *) cmd);
145-
memset(cmd + rr, rand() & 0xFFu, sizeof(cmd) - rr);
146-
mp_read_unsigned_bin(&d, (unsigned char *) cmd, rr);
145+
memset(cmd + rr, rand() & 0xFF, sizeof(cmd) - rr);
146+
mp_read_unsigned_bin(&d, (unsigned char *) cmd, (int)rr);
147147
if (mp_cmp_mag(&c, &d) != MP_EQ) {
148148
printf("mp_unsigned_bin failure!\n");
149149
draw(&c);
@@ -343,7 +343,7 @@ int mtest_opponent(void)
343343
sscanf(buf, "%d", &ix);
344344
FGETS(buf, 4095, stdin);
345345
mp_read_radix(&b, buf, 64);
346-
mp_add_d(&a, ix, &c);
346+
mp_add_d(&a, (mp_digit)ix, &c);
347347
if (mp_cmp(&b, &c) != MP_EQ) {
348348
printf("add_d %lu failure\n", add_d_n);
349349
draw(&a);
@@ -360,7 +360,7 @@ int mtest_opponent(void)
360360
sscanf(buf, "%d", &ix);
361361
FGETS(buf, 4095, stdin);
362362
mp_read_radix(&b, buf, 64);
363-
mp_sub_d(&a, ix, &c);
363+
mp_sub_d(&a, (mp_digit)ix, &c);
364364
if (mp_cmp(&b, &c) != MP_EQ) {
365365
printf("sub_d %lu failure\n", sub_d_n);
366366
draw(&a);

0 commit comments

Comments
 (0)