From 179daef1233d4c464a1f649c0b8a8db1761574af Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Sat, 6 Apr 2019 17:37:33 +0200 Subject: [PATCH 1/6] add travis-build to check source-code format --- .travis.yml | 8 ++++++++ testme.sh | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/.travis.yml b/.travis.yml index 743d621cf..84610044a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,6 +57,14 @@ matrix: # We have only one program and the variable $BUILDOPTIONS # has only the options to that program: testme.sh + # Check source code format + - env: BUILDOPTIONS='--format' + addons: + apt: + packages: + - astyle + sudo: required + # GCC for the 32-bit architecture (no valgrind yet) - env: BUILDOPTIONS='--with-cc=gcc --with-m32' addons: diff --git a/testme.sh b/testme.sh index b340df1c9..40ecb74f7 100755 --- a/testme.sh +++ b/testme.sh @@ -72,6 +72,10 @@ _help() echo " --all Choose all architectures and gcc and clang" echo " as compilers but does not run valgrind." echo + echo " --format Runs the various source-code formatters" + echo " and generators and checks if the sources" + echo " are clean." + echo echo " -h" echo " --help This message" echo @@ -168,6 +172,7 @@ MTEST_RAND="" VALGRIND_OPTS=" --leak-check=full --show-leak-kinds=all --error-exitcode=1 " #VALGRIND_OPTS="" VALGRIND_BIN="" +CHECK_FORMAT="" alive_pid=0 @@ -225,6 +230,9 @@ do --mtest-real-rand) MTEST_RAND="-DLTM_MTEST_REAL_RAND" ;; + --format) + CHECK_FORMAT="1" + ;; --all) COMPILERS="gcc clang" ARCHFLAGS="-m64 -m32 -mx32" @@ -243,6 +251,21 @@ do shift done +function _check_git() { + git update-index --refresh >/dev/null || true + git diff-index --quiet HEAD -- . || ( echo "FAILURE: $*" && exit 1 ) +} + +if [[ "$CHECK_FORMAT" == "1" ]] +then + make astyle + _check_git "make astyle" + make new_file + _check_git "make format" + perl helper.pl -a + exit $? +fi + [[ "$VALGRIND_BIN" == "" ]] && VALGRIND_OPTS="" # default to CC environment variable if no compiler is defined but some other options From cf807537646dcd419ec151e160ee2e84fd65571a Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Sat, 6 Apr 2019 17:37:48 +0200 Subject: [PATCH 2/6] run `make astyle` --- bn_mp_clear.c | 2 +- bn_mp_grow.c | 2 +- bn_mp_shrink.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bn_mp_clear.c b/bn_mp_clear.c index b8e724cfc..9b8a233ef 100644 --- a/bn_mp_clear.c +++ b/bn_mp_clear.c @@ -25,7 +25,7 @@ void mp_clear(mp_int *a) } /* free ram */ - XFREE(a->dp, sizeof (mp_digit) * (size_t)a->alloc); + XFREE(a->dp, sizeof(mp_digit) * (size_t)a->alloc); /* reset members to make debugging easier */ a->dp = NULL; diff --git a/bn_mp_grow.c b/bn_mp_grow.c index b12019414..db1d06e51 100644 --- a/bn_mp_grow.c +++ b/bn_mp_grow.c @@ -30,7 +30,7 @@ int mp_grow(mp_int *a, int size) * to overwrite the dp member of a. */ tmp = (mp_digit *) XREALLOC(a->dp, - (size_t)a->alloc * sizeof (mp_digit), + (size_t)a->alloc * sizeof(mp_digit), (size_t)size * sizeof(mp_digit)); if (tmp == NULL) { /* reallocation failed but "a" is still valid [can be freed] */ diff --git a/bn_mp_shrink.c b/bn_mp_shrink.c index fa30184aa..04c88e361 100644 --- a/bn_mp_shrink.c +++ b/bn_mp_shrink.c @@ -24,7 +24,7 @@ int mp_shrink(mp_int *a) if (a->alloc != used) { if ((tmp = (mp_digit *) XREALLOC(a->dp, - (size_t)a->alloc * sizeof (mp_digit), + (size_t)a->alloc * sizeof(mp_digit), (size_t)used * sizeof(mp_digit))) == NULL) { return MP_MEM; } From 58e9084e1a01b8ef1d81f2e8bb538b77f2105372 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Sat, 6 Apr 2019 17:38:41 +0200 Subject: [PATCH 3/6] run `make new_file` --- callgraph.txt | 45 --------------------------------------------- tommath_class.h | 2 -- 2 files changed, 47 deletions(-) diff --git a/callgraph.txt b/callgraph.txt index afcfa0504..2a9aed050 100644 --- a/callgraph.txt +++ b/callgraph.txt @@ -2416,8 +2416,6 @@ BN_MP_INIT_SET_INT_C +--->BN_MP_INIT_C +--->BN_MP_SET_INT_C | +--->BN_MP_SET_LONG_C -| | +--->BN_MP_GROW_C -| | +--->BN_MP_ZERO_C BN_MP_INIT_SIZE_C @@ -2743,8 +2741,6 @@ BN_MP_IS_SQUARE_C | +--->BN_MP_INIT_C | +--->BN_MP_SET_INT_C | | +--->BN_MP_SET_LONG_C -| | | +--->BN_MP_GROW_C -| | | +--->BN_MP_ZERO_C +--->BN_MP_MOD_C | +--->BN_MP_INIT_SIZE_C | | +--->BN_MP_INIT_C @@ -5659,8 +5655,6 @@ BN_MP_PRIME_FROBENIUS_UNDERWOOD_C | | | +--->BN_MP_INIT_C | | | +--->BN_MP_SET_INT_C | | | | +--->BN_MP_SET_LONG_C -| | | | | +--->BN_MP_GROW_C -| | | | | +--->BN_MP_ZERO_C | | +--->BN_MP_MOD_C | | | +--->BN_MP_INIT_SIZE_C | | | | +--->BN_MP_INIT_C @@ -7264,8 +7258,6 @@ BN_MP_PRIME_FROBENIUS_UNDERWOOD_C | | | +--->BN_MP_CLAMP_C | | +--->BN_MP_INIT_C | | +--->BN_MP_SET_LONG_C -| | | +--->BN_MP_GROW_C -| | | +--->BN_MP_ZERO_C | | +--->BN_MP_MUL_C | | | +--->BN_MP_TOOM_MUL_C | | | | +--->BN_MP_INIT_MULTI_C @@ -7616,8 +7608,6 @@ BN_MP_PRIME_FROBENIUS_UNDERWOOD_C | +--->BN_MP_INIT_C | +--->BN_MP_CLEAR_C +--->BN_MP_SET_LONG_C -| +--->BN_MP_GROW_C -| +--->BN_MP_ZERO_C +--->BN_MP_SQR_C | +--->BN_MP_TOOM_SQR_C | | +--->BN_MP_MOD_2D_C @@ -7975,8 +7965,6 @@ BN_MP_PRIME_IS_PRIME_C | | +--->BN_MP_INIT_C | | +--->BN_MP_SET_INT_C | | | +--->BN_MP_SET_LONG_C -| | | | +--->BN_MP_GROW_C -| | | | +--->BN_MP_ZERO_C | +--->BN_MP_MOD_C | | +--->BN_MP_INIT_SIZE_C | | | +--->BN_MP_INIT_C @@ -9579,8 +9567,6 @@ BN_MP_PRIME_IS_PRIME_C | | +--->BN_MP_INIT_C | | +--->BN_MP_CLEAR_C | +--->BN_MP_SET_LONG_C -| | +--->BN_MP_GROW_C -| | +--->BN_MP_ZERO_C | +--->BN_MP_SQR_C | | +--->BN_MP_TOOM_SQR_C | | | +--->BN_MP_MOD_2D_C @@ -9890,8 +9876,6 @@ BN_MP_PRIME_IS_PRIME_C | | +--->BN_MP_CLAMP_C | +--->BN_MP_INIT_C | +--->BN_MP_SET_LONG_C -| | +--->BN_MP_GROW_C -| | +--->BN_MP_ZERO_C | +--->BN_MP_MUL_C | | +--->BN_MP_TOOM_MUL_C | | | +--->BN_MP_INIT_MULTI_C @@ -11371,8 +11355,6 @@ BN_MP_PRIME_NEXT_PRIME_C | | +--->BN_MP_INIT_SET_INT_C | | | +--->BN_MP_SET_INT_C | | | | +--->BN_MP_SET_LONG_C -| | | | | +--->BN_MP_GROW_C -| | | | | +--->BN_MP_ZERO_C | | +--->BN_MP_MOD_C | | | +--->BN_MP_INIT_SIZE_C | | | +--->BN_MP_DIV_C @@ -12909,8 +12891,6 @@ BN_MP_PRIME_NEXT_PRIME_C | | +--->BN_MP_INIT_MULTI_C | | | +--->BN_MP_CLEAR_C | | +--->BN_MP_SET_LONG_C -| | | +--->BN_MP_GROW_C -| | | +--->BN_MP_ZERO_C | | +--->BN_MP_SQR_C | | | +--->BN_MP_TOOM_SQR_C | | | | +--->BN_MP_MOD_2D_C @@ -13200,8 +13180,6 @@ BN_MP_PRIME_NEXT_PRIME_C | | | +--->BN_MP_GROW_C | | | +--->BN_MP_CLAMP_C | | +--->BN_MP_SET_LONG_C -| | | +--->BN_MP_GROW_C -| | | +--->BN_MP_ZERO_C | | +--->BN_MP_MUL_C | | | +--->BN_MP_TOOM_MUL_C | | | | +--->BN_MP_INIT_MULTI_C @@ -13568,8 +13546,6 @@ BN_MP_PRIME_RANDOM_EX_C | | | +--->BN_MP_INIT_C | | | +--->BN_MP_SET_INT_C | | | | +--->BN_MP_SET_LONG_C -| | | | | +--->BN_MP_GROW_C -| | | | | +--->BN_MP_ZERO_C | | +--->BN_MP_MOD_C | | | +--->BN_MP_INIT_SIZE_C | | | | +--->BN_MP_INIT_C @@ -15172,8 +15148,6 @@ BN_MP_PRIME_RANDOM_EX_C | | | +--->BN_MP_INIT_C | | | +--->BN_MP_CLEAR_C | | +--->BN_MP_SET_LONG_C -| | | +--->BN_MP_GROW_C -| | | +--->BN_MP_ZERO_C | | +--->BN_MP_SQR_C | | | +--->BN_MP_TOOM_SQR_C | | | | +--->BN_MP_MOD_2D_C @@ -15483,8 +15457,6 @@ BN_MP_PRIME_RANDOM_EX_C | | | +--->BN_MP_CLAMP_C | | +--->BN_MP_INIT_C | | +--->BN_MP_SET_LONG_C -| | | +--->BN_MP_GROW_C -| | | +--->BN_MP_ZERO_C | | +--->BN_MP_MUL_C | | | +--->BN_MP_TOOM_MUL_C | | | | +--->BN_MP_INIT_MULTI_C @@ -15874,8 +15846,6 @@ BN_MP_PRIME_STRONG_LUCAS_SELFRIDGE_C | | | +--->BN_MP_INIT_C | | | +--->BN_MP_SET_INT_C | | | | +--->BN_MP_SET_LONG_C -| | | | | +--->BN_MP_GROW_C -| | | | | +--->BN_MP_ZERO_C | | +--->BN_MP_MOD_C | | | +--->BN_MP_INIT_SIZE_C | | | | +--->BN_MP_INIT_C @@ -17478,8 +17448,6 @@ BN_MP_PRIME_STRONG_LUCAS_SELFRIDGE_C | | | +--->BN_MP_INIT_C | | | +--->BN_MP_CLEAR_C | | +--->BN_MP_SET_LONG_C -| | | +--->BN_MP_GROW_C -| | | +--->BN_MP_ZERO_C | | +--->BN_MP_SQR_C | | | +--->BN_MP_TOOM_SQR_C | | | | +--->BN_MP_MOD_2D_C @@ -17822,8 +17790,6 @@ BN_MP_PRIME_STRONG_LUCAS_SELFRIDGE_C | +--->BN_MP_CLAMP_C +--->BN_MP_INIT_C +--->BN_MP_SET_LONG_C -| +--->BN_MP_GROW_C -| +--->BN_MP_ZERO_C +--->BN_MP_MUL_C | +--->BN_MP_TOOM_MUL_C | | +--->BN_MP_INIT_MULTI_C @@ -18666,13 +18632,9 @@ BN_MP_SET_DOUBLE_C BN_MP_SET_INT_C +--->BN_MP_SET_LONG_C -| +--->BN_MP_GROW_C -| +--->BN_MP_ZERO_C BN_MP_SET_LONG_C -+--->BN_MP_GROW_C -+--->BN_MP_ZERO_C BN_MP_SET_LONG_LONG_C @@ -19855,7 +19817,6 @@ BN_MP_SQRTMOD_PRIME_C | +--->BN_MP_CLAMP_C +--->BN_MP_SET_INT_C | +--->BN_MP_SET_LONG_C -| | +--->BN_MP_GROW_C +--->BN_MP_SQRMOD_C | +--->BN_MP_INIT_C | +--->BN_MP_SQR_C @@ -20593,8 +20554,6 @@ BN_MP_TC_AND_C | +--->BN_MP_INIT_C | +--->BN_MP_SET_INT_C | | +--->BN_MP_SET_LONG_C -| | | +--->BN_MP_GROW_C -| | | +--->BN_MP_ZERO_C +--->BN_MP_MUL_2D_C | +--->BN_MP_COPY_C | | +--->BN_MP_GROW_C @@ -20655,8 +20614,6 @@ BN_MP_TC_OR_C | +--->BN_MP_INIT_C | +--->BN_MP_SET_INT_C | | +--->BN_MP_SET_LONG_C -| | | +--->BN_MP_GROW_C -| | | +--->BN_MP_ZERO_C +--->BN_MP_MUL_2D_C | +--->BN_MP_COPY_C | | +--->BN_MP_GROW_C @@ -20698,8 +20655,6 @@ BN_MP_TC_XOR_C | +--->BN_MP_INIT_C | +--->BN_MP_SET_INT_C | | +--->BN_MP_SET_LONG_C -| | | +--->BN_MP_GROW_C -| | | +--->BN_MP_ZERO_C +--->BN_MP_MUL_2D_C | +--->BN_MP_COPY_C | | +--->BN_MP_GROW_C diff --git a/tommath_class.h b/tommath_class.h index 84fbd5368..96b2ba02e 100644 --- a/tommath_class.h +++ b/tommath_class.h @@ -937,8 +937,6 @@ #endif #if defined(BN_MP_SET_LONG_C) -# define BN_MP_GROW_C -# define BN_MP_ZERO_C #endif #if defined(BN_MP_SET_LONG_LONG_C) From 6f5df266f2a01c24200e423656bcef88a0d5a82a Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Sat, 6 Apr 2019 17:40:46 +0200 Subject: [PATCH 4/6] fix file headers & footers --- bn_mp_decr.c | 9 ++++----- bn_mp_incr.c | 8 ++++---- bn_mp_iseven.c | 3 +-- bn_mp_isodd.c | 3 +-- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/bn_mp_decr.c b/bn_mp_decr.c index b57f5d099..edf65f490 100644 --- a/bn_mp_decr.c +++ b/bn_mp_decr.c @@ -40,9 +40,8 @@ int mp_decr(mp_int *a) } return mp_sub_d(a, 1uL,a); } - - #endif -/* ref: \$Format:\%D$ */ -/* git commit: \$Format:\%H$ */ -/* commit time: \$Format:\%ai$ */ + +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/bn_mp_incr.c b/bn_mp_incr.c index b7cd24a60..adecb2529 100644 --- a/bn_mp_incr.c +++ b/bn_mp_incr.c @@ -35,8 +35,8 @@ int mp_incr(mp_int *a) } return mp_add_d(a, 1uL,a); } - #endif -/* ref: \$Format:\%D$ */ -/* git commit: \$Format:\%H$ */ -/* commit time: \$Format:\%ai$ */ + +/* ref: $Format:%D$ */ +/* git commit: $Format:%H$ */ +/* commit time: $Format:%ai$ */ diff --git a/bn_mp_iseven.c b/bn_mp_iseven.c index 4dc72a474..9532fdd30 100644 --- a/bn_mp_iseven.c +++ b/bn_mp_iseven.c @@ -9,8 +9,7 @@ * Michael Fromberger but has been written from scratch with * additional optimizations in place. * - * The library is free for all purposes without any express - * guarantee it works. + * SPDX-License-Identifier: Unlicense */ int mp_iseven(const mp_int *a) diff --git a/bn_mp_isodd.c b/bn_mp_isodd.c index 4a3942c3b..007b6dd90 100644 --- a/bn_mp_isodd.c +++ b/bn_mp_isodd.c @@ -9,8 +9,7 @@ * Michael Fromberger but has been written from scratch with * additional optimizations in place. * - * The library is free for all purposes without any express - * guarantee it works. + * SPDX-License-Identifier: Unlicense */ int mp_isodd(const mp_int *a) From 6dc923efa98aad2b0708afe64c3106df3a134cf8 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Sat, 6 Apr 2019 17:45:05 +0200 Subject: [PATCH 5/6] clean-up `make astyle` output --- makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index 484222f90..b31cd253a 100644 --- a/makefile +++ b/makefile @@ -156,4 +156,5 @@ perlcritic: perlcritic *.pl doc/*.pl astyle: - astyle --options=astylerc $(OBJECTS:.o=.c) tommath*.h demo/*.c etc/*.c mtest/mtest.c + @echo " * run astyle on all sources" + @astyle --options=astylerc --formatted $(OBJECTS:.o=.c) tommath*.h demo/*.c etc/*.c mtest/mtest.c From c4bb3c1bd43c689cd8fa67ad832c364f655bc9ca Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Sat, 6 Apr 2019 17:59:49 +0200 Subject: [PATCH 6/6] let's see if the xenial version of astyle is better --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 84610044a..047939dd9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,9 @@ # # ############################################################################# +# Run the tests based on Ubuntu 16.04 +dist: xenial + # Compilation failures are in gcc_errors_*.log # Failed tests in test_*.log # Files do not exist in case of success