@@ -1187,8 +1187,8 @@ static int test_mp_montgomery_reduce(void)
11871187{
11881188 mp_digit mp ;
11891189 int ix , i , n ;
1190- char buf [ 4096 ] ;
1191- size_t length [ 1 ];
1190+ char * buf = NULL ;
1191+ /* size_t written; */
11921192
11931193 mp_int a , b , c , d , e ;
11941194 if (mp_init_multi (& a , & b , & c , & d , & e , NULL )!= MP_OKAY ) {
@@ -1222,17 +1222,18 @@ static int test_mp_montgomery_reduce(void)
12221222 if (mp_cmp (& c , & d ) != MP_EQ ) {
12231223/* *INDENT-OFF* */
12241224 printf ("d = e mod a, c = e MOD a\n" );
1225- * length = sizeof (buf );
1226- mp_to_radix (& a , buf , length , 10 ); printf ("a = %s, length = %zu\n" , buf , * length );
1227- mp_to_radix (& e , buf , length , 10 ); printf ("e = %s, length = %zu\n" , buf , * length );
1228- mp_to_radix (& d , buf , length , 10 ); printf ("d = %s, length = %zu\n" , buf , * length );
1229- mp_to_radix (& c , buf , length , 10 ); printf ("c = %s, length = %zu\n" , buf , * length );
12301225/*
1231- mp_to_decimal (&a, buf, sizeof(buf)) ; printf("a = %s\n", buf);
1232- mp_to_decimal (&e, buf, sizeof(buf)) ; printf("e = %s\n", buf);
1233- mp_to_decimal (&d, buf, sizeof(buf)) ; printf("d = %s\n", buf);
1234- mp_to_decimal (&c, buf, sizeof(buf)) ; printf("c = %s\n", buf);
1226+ mp_to_radix (&a, & buf, 0u, &written, 10) ; printf("a = %s, written = %zu \n", buf, written );
1227+ mp_to_radix (&e, & buf, 0u, &written, 10) ; printf("e = %s, written = %zu \n", buf, written );
1228+ mp_to_radix (&d, & buf, 0u, &written, 10) ; printf("d = %s, written = %zu \n", buf, written );
1229+ mp_to_radix (&c, & buf, 0u, &written, 10) ; printf("c = %s, written = %zu \n", buf, written );
12351230*/
1231+
1232+ mp_to_decimal (& a , & buf , 0u ); printf ("a = %s\n" , buf );
1233+ mp_to_decimal (& e , & buf , 0u ); printf ("e = %s\n" , buf );
1234+ mp_to_decimal (& d , & buf , 0u ); printf ("d = %s\n" , buf );
1235+ mp_to_decimal (& c , & buf , 0u ); printf ("c = %s\n" , buf );
1236+
12361237 printf ("compare no compare!\n" ); goto LBL_ERR ;
12371238/* *INDENT-ON* */
12381239 }
@@ -1246,46 +1247,47 @@ static int test_mp_montgomery_reduce(void)
12461247 }
12471248
12481249 printf ("\n\n" );
1250+ free (buf );
12491251
12501252 mp_clear_multi (& a , & b , & c , & d , & e , NULL );
12511253 return EXIT_SUCCESS ;
12521254LBL_ERR :
1255+ free (buf );
12531256 mp_clear_multi (& a , & b , & c , & d , & e , NULL );
12541257 return EXIT_FAILURE ;
12551258
12561259}
12571260
12581261static int test_mp_read_radix (void )
12591262{
1260- char buf [ 4096 ] ;
1261- size_t length [ 1 ] ;
1263+ char * buf = NULL ;
1264+ size_t written ;
12621265
12631266 mp_int a ;
12641267 if (mp_init_multi (& a , NULL )!= MP_OKAY ) {
12651268 return EXIT_FAILURE ;
12661269 }
12671270
12681271 mp_read_radix (& a , "123456" , 10 );
1269- * length = 3u ;
1270- mp_to_radix (& a , buf , length , 10 );
1271- printf ("a == %s, length = %zu\n" , buf , * length );
1272- * length = 4u ;
1273- mp_to_radix (& a , buf , length , 10 );
1274- printf ("a == %s, length = %zu\n" , buf , * length );
1275- * length = 30u ;
1276- mp_to_radix (& a , buf , length , 10 );
1277- printf ("a == %s, length = %zu\n" , buf , * length );
1272+
1273+ mp_to_radix (& a , & buf , 3u , & written , 10 );
1274+ printf ("a == %s, length = %zu\n" , buf , written );
1275+ mp_to_radix (& a , & buf , 4u , & written , 10 );
1276+ printf ("a == %s, length = %zu\n" , buf , written );
1277+ mp_to_radix (& a , & buf , 30u , & written , 10 );
1278+ printf ("a == %s, length = %zu\n" , buf , written );
12781279
12791280 while (0 ) {
1280- char * s = fgets (buf , sizeof (buf ), stdin );
1281- if (s != buf ) break ;
1282- mp_read_radix (& a , buf , 10 );
1281+ char line_buffer [4096 ];
1282+ char * s = fgets (line_buffer , sizeof (line_buffer ), stdin );
1283+ if (s != line_buffer ) break ;
1284+ mp_read_radix (& a , line_buffer , 10 );
12831285 mp_prime_next_prime (& a , 5 , 1 );
1284- * length = sizeof (buf );
1285- mp_to_radix (& a , buf , length , 10 );
1286+ mp_to_radix (& a , & buf , 0u , NULL , 10 );
12861287 printf ("%s, %lu\n" , buf , (unsigned long )a .dp [0 ] & 3uL );
12871288 }
12881289
1290+ free (buf );
12891291 mp_clear_multi (& a , NULL );
12901292 return EXIT_SUCCESS ;
12911293}
@@ -1838,6 +1840,7 @@ static int test_mp_decr(void)
18381840 All numbers as strings to simplifiy things, especially for the
18391841 low-mp branch.
18401842*/
1843+
18411844static int test_mp_root_u32 (void )
18421845{
18431846 mp_int a , c , r ;
0 commit comments