From 3e3d2b818ca0ffdca6f39105f3804a6e4d3f40e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 21 Nov 2013 21:12:26 +0100 Subject: [PATCH] Fix bug in mpi_safe_cond_assign() --- library/bignum.c | 1 + tests/suites/test_suite_mpi.data | 15 ++++++++++++--- tests/suites/test_suite_mpi.function | 5 ++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/library/bignum.c b/library/bignum.c index 663d9240e..49321bb65 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -222,6 +222,7 @@ int mpi_safe_cond_assign( mpi *X, mpi *Y, unsigned char assign ) MPI_CHK( mpi_grow( X, Y->n ) ); /* Do the conditional assign safely */ + X->s = X->s * (1 - assign) + Y->s * assign; for( i = 0; i < X->n; i++ ) X->p[i] = X->p[i] * (1 - assign) + Y->p[i] * assign; diff --git a/tests/suites/test_suite_mpi.data b/tests/suites/test_suite_mpi.data index 8755fa29a..287cc2d05 100644 --- a/tests/suites/test_suite_mpi.data +++ b/tests/suites/test_suite_mpi.data @@ -206,13 +206,22 @@ Test mpi_shrink #8 mpi_shrink:4:0:0:1 Test mpi_safe_cond_assign #1 -mpi_safe_cond_assign:"01":"02" +mpi_safe_cond_assign:+1:"01":+1:"02" Test mpi_safe_cond_assign #2 -mpi_safe_cond_assign:"FF000000000000000001":"02" +mpi_safe_cond_assign:+1:"FF000000000000000001":+1:"02" Test mpi_safe_cond_assign #3 -mpi_safe_cond_assign:"01":"FF000000000000000002" +mpi_safe_cond_assign:+1:"01":+1:"FF000000000000000002" + +Test mpi_safe_cond_assign #4 +mpi_safe_cond_assign:+1:"01":-1:"02" + +Test mpi_safe_cond_assign #5 +mpi_safe_cond_assign:-1:"01":+1:"02" + +Test mpi_safe_cond_assign #6 +mpi_safe_cond_assign:-1:"01":-1:"02" Base test mpi_add_abs #1 mpi_add_abs:10:"12345678":10:"642531":10:"12988209" diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function index ee9b94a5b..394cd339b 100644 --- a/tests/suites/test_suite_mpi.function +++ b/tests/suites/test_suite_mpi.function @@ -309,13 +309,16 @@ void mpi_shrink( int before, int used, int min, int after ) /* END_CASE */ /* BEGIN_CASE */ -void mpi_safe_cond_assign( char *x_str, char *y_str ) +void mpi_safe_cond_assign( int x_sign, char *x_str, + int y_sign, char *y_str ) { mpi X, Y, XX; mpi_init( &X ); mpi_init( &Y ); mpi_init( &XX ); TEST_ASSERT( mpi_read_string( &X, 16, x_str ) == 0 ); + X.s = x_sign; TEST_ASSERT( mpi_read_string( &Y, 16, y_str ) == 0 ); + Y.s = y_sign; TEST_ASSERT( mpi_copy( &XX, &X ) == 0 ); TEST_ASSERT( mpi_safe_cond_assign( &X, &Y, 0 ) == 0 );