From 70bc075f8d35de632aeaf8603bbad025969ff38c Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Tue, 29 Oct 2019 20:26:50 +0100 Subject: [PATCH] apply a series of simplifications * this is the final commit of a series of simplifications, containing only the regenerated files and the explanation in the commit message * This is in preparation of the size_t change/a potential representation change to use full width as in tfm, if a (partial?) merge with tfm is desired. These changes have their own merits however. * Remove obfuscating tmpx digit pointers (fewer variables, it is more obvious what is being manipulated) * Reduce scope of variables where possible * Stricter error handling/checking (for example handling in karatsuba was broken) * In some cases the result was written even in the case of an error (e.g. s_mp_is_divisible). This will hide bugs, since the user should check the return value (enforced by MP_WUR). Furthermore if the user accesses the non-initialized result, valgrind will complain for example. Global static analysis like coverity will also detect the issue. Therefore this improves the status quo. * Introduce generic, private MP_EXCH macro which can be used to swap values. * Introduce s_mp_copy_digs/s_mp_zero_digs/s_mp_zero_buf * Some control flow simplifications, e.g, loops instead of goto * Renamings of variables/labels for consistency * Renamings of mul/sqr functions for more consistency, e.g., comba instead of fast suffix * I didn't read through some very complex functions. They are so complex, I am too afraid and lazy to touch them. Maybe someone resposible wants to simplify them if possible. Hint... Hint... - mp_prime_strong_lucas_selfridge.c - s_mp_exptmod.c - s_mp_exptmod_fast.c --- helper.pl | 5 +- libtommath_VS2008.vcproj | 48 +++++---- makefile | 32 +++--- makefile.mingw | 32 +++--- makefile.msvc | 32 +++--- makefile.shared | 32 +++--- makefile.unix | 32 +++--- tommath.def | 1 - tommath_class.h | 228 +++++++++++++++++++++++---------------- 9 files changed, 243 insertions(+), 199 deletions(-) diff --git a/helper.pl b/helper.pl index 223c7ef60..2378ccea8 100755 --- a/helper.pl +++ b/helper.pl @@ -57,9 +57,8 @@ sub check_source { push @{$troubles->{unwanted_calloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bcalloc\s*\(/; push @{$troubles->{unwanted_free}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bfree\s*\(/; # and we probably want to also avoid the following - push @{$troubles->{unwanted_memcpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemcpy\s*\(/; - push @{$troubles->{unwanted_memset}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemset\s*\(/; - push @{$troubles->{unwanted_memcpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemcpy\s*\(/; + #push @{$troubles->{unwanted_memcpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemcpy\s*\(/; + #push @{$troubles->{unwanted_memset}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemset\s*\(/; push @{$troubles->{unwanted_memmove}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemmove\s*\(/; push @{$troubles->{unwanted_memcmp}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemcmp\s*\(/; push @{$troubles->{unwanted_strcmp}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bstrcmp\s*\(/; diff --git a/libtommath_VS2008.vcproj b/libtommath_VS2008.vcproj index 116275e8d..07c784bf9 100644 --- a/libtommath_VS2008.vcproj +++ b/libtommath_VS2008.vcproj @@ -576,10 +576,6 @@ RelativePath="mp_mod_2d.c" > - - @@ -833,7 +829,7 @@ > + + + + + +