diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e3098cd9..4d17af826 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,7 +135,7 @@ if(CMAKE_COMPILER_IS_GNU) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op") endif() if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow -Wformat-signedness") endif() set(CMAKE_C_FLAGS_RELEASE "-O2") set(CMAKE_C_FLAGS_DEBUG "-O0 -g3") diff --git a/ChangeLog.d/fix-gcc-format-signedness-warnings.txt b/ChangeLog.d/fix-gcc-format-signedness-warnings.txt new file mode 100644 index 000000000..023d15c8e --- /dev/null +++ b/ChangeLog.d/fix-gcc-format-signedness-warnings.txt @@ -0,0 +1,3 @@ +Changes + * Fix warnings about signedness issues in format strings. The build is now + clean of -Wformat-signedness warnings. Contributed by Kenneth Soerensen in #3153. diff --git a/library/aes.c b/library/aes.c index 604d0f3d7..962b0b92a 100644 --- a/library/aes.c +++ b/library/aes.c @@ -1847,7 +1847,7 @@ int mbedtls_aes_self_test( int verbose ) mode = i & 1; if( verbose != 0 ) - mbedtls_printf( " AES-ECB-%3d (%s): ", keybits, + mbedtls_printf( " AES-ECB-%3u (%s): ", keybits, ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); memset( buf, 0, 16 ); @@ -1909,7 +1909,7 @@ int mbedtls_aes_self_test( int verbose ) mode = i & 1; if( verbose != 0 ) - mbedtls_printf( " AES-CBC-%3d (%s): ", keybits, + mbedtls_printf( " AES-CBC-%3u (%s): ", keybits, ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); memset( iv , 0, 16 ); @@ -1984,7 +1984,7 @@ int mbedtls_aes_self_test( int verbose ) mode = i & 1; if( verbose != 0 ) - mbedtls_printf( " AES-CFB128-%3d (%s): ", keybits, + mbedtls_printf( " AES-CFB128-%3u (%s): ", keybits, ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); memcpy( iv, aes_test_cfb128_iv, 16 ); @@ -2047,7 +2047,7 @@ int mbedtls_aes_self_test( int verbose ) mode = i & 1; if( verbose != 0 ) - mbedtls_printf( " AES-OFB-%3d (%s): ", keybits, + mbedtls_printf( " AES-OFB-%3u (%s): ", keybits, ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); memcpy( iv, aes_test_ofb_iv, 16 ); diff --git a/library/bignum.c b/library/bignum.c index d53aefd5b..d56a16e76 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -2938,7 +2938,7 @@ int mbedtls_mpi_self_test( int verbose ) cleanup: if( ret != 0 && verbose != 0 ) - mbedtls_printf( "Unexpected error, return code = %08X\n", ret ); + mbedtls_printf( "Unexpected error, return code = %08X\n", (unsigned int) ret ); mbedtls_mpi_free( &A ); mbedtls_mpi_free( &E ); mbedtls_mpi_free( &N ); mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &U ); mbedtls_mpi_free( &V ); diff --git a/library/cmac.c b/library/cmac.c index 642680d55..2d23be5ff 100644 --- a/library/cmac.c +++ b/library/cmac.c @@ -784,7 +784,7 @@ static int cmac_test_subkeys( int verbose, for( i = 0; i < num_tests; i++ ) { if( verbose != 0 ) - mbedtls_printf( " %s CMAC subkey #%u: ", testname, i + 1 ); + mbedtls_printf( " %s CMAC subkey #%d: ", testname, i + 1 ); mbedtls_cipher_init( &ctx ); @@ -865,7 +865,7 @@ static int cmac_test_wth_cipher( int verbose, for( i = 0; i < num_tests; i++ ) { if( verbose != 0 ) - mbedtls_printf( " %s CMAC #%u: ", testname, i + 1 ); + mbedtls_printf( " %s CMAC #%d: ", testname, i + 1 ); if( ( ret = mbedtls_cipher_cmac( cipher_info, key, keybits, messages, message_lengths[i], output ) ) != 0 ) @@ -900,7 +900,7 @@ static int test_aes128_cmac_prf( int verbose ) for( i = 0; i < NB_PRF_TESTS; i++ ) { - mbedtls_printf( " AES CMAC 128 PRF #%u: ", i ); + mbedtls_printf( " AES CMAC 128 PRF #%d: ", i ); ret = mbedtls_aes_cmac_prf_128( PRFK, PRFKlen[i], PRFM, 20, output ); if( ret != 0 || memcmp( output, PRFT[i], MBEDTLS_AES_BLOCK_SIZE ) != 0 ) diff --git a/library/debug.c b/library/debug.c index ae78a697a..2b25e997c 100644 --- a/library/debug.c +++ b/library/debug.c @@ -132,7 +132,7 @@ void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level, return; mbedtls_snprintf( str, sizeof( str ), "%s() returned %d (-0x%04x)\n", - text, ret, -ret ); + text, ret, (unsigned int) -ret ); debug_send_line( ssl, level, file, line, str ); } diff --git a/library/ecp.c b/library/ecp.c index d3e42a94d..fa91b3ec2 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -3156,7 +3156,7 @@ int mbedtls_ecp_self_test( int verbose ) cleanup: if( ret < 0 && verbose != 0 ) - mbedtls_printf( "Unexpected error, return code = %08X\n", ret ); + mbedtls_printf( "Unexpected error, return code = %08X\n", (unsigned int) ret ); mbedtls_ecp_group_free( &grp ); mbedtls_ecp_point_free( &R ); diff --git a/library/error.c b/library/error.c index 38b658006..d2f1b18a3 100644 --- a/library/error.c +++ b/library/error.c @@ -1171,7 +1171,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) high_level_error_description = mbedtls_high_level_strerr( ret ); if( high_level_error_description == NULL ) - mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret ); + mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret ); else mbedtls_snprintf( buf, buflen, "%s", high_level_error_description ); @@ -1208,7 +1208,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) low_level_error_description = mbedtls_low_level_strerr( ret ); if( low_level_error_description == NULL ) - mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret ); + mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret ); else mbedtls_snprintf( buf, buflen, "%s", low_level_error_description ); } diff --git a/library/oid.c b/library/oid.c index 891d3cdea..e0c074369 100644 --- a/library/oid.c +++ b/library/oid.c @@ -761,7 +761,7 @@ int mbedtls_oid_get_numeric_string( char *buf, size_t size, if( !( oid->p[i] & 0x80 ) ) { /* Last byte */ - ret = mbedtls_snprintf( p, n, ".%d", value ); + ret = mbedtls_snprintf( p, n, ".%u", value ); OID_SAFE_SNPRINTF; value = 0; } diff --git a/library/x509.c b/library/x509.c index c451332c2..4c2f72105 100644 --- a/library/x509.c +++ b/library/x509.c @@ -870,7 +870,7 @@ int mbedtls_x509_sig_alg_gets( char *buf, size_t size, const mbedtls_x509_buf *s ret = mbedtls_snprintf( p, n, " (%s, MGF1-%s, 0x%02X)", md_info ? mbedtls_md_get_name( md_info ) : "???", mgf_md_info ? mbedtls_md_get_name( mgf_md_info ) : "???", - pss_opts->expected_salt_len ); + (unsigned int) pss_opts->expected_salt_len ); MBEDTLS_X509_SAFE_SNPRINTF; } #else diff --git a/programs/aes/aescrypt2.c b/programs/aes/aescrypt2.c index 048028df0..8edf85f33 100644 --- a/programs/aes/aescrypt2.c +++ b/programs/aes/aescrypt2.c @@ -118,7 +118,7 @@ int main( int argc, char *argv[] ) ret = mbedtls_md_setup( &sha_ctx, mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ), 1 ); if( ret != 0 ) { - mbedtls_printf( " ! mbedtls_md_setup() returned -0x%04x\n", -ret ); + mbedtls_printf( " ! mbedtls_md_setup() returned -0x%04x\n", (unsigned int) -ret ); goto exit; } @@ -298,7 +298,7 @@ int main( int argc, char *argv[] ) if( fread( buffer, 1, n, fin ) != (size_t) n ) { - mbedtls_fprintf( stderr, "fread(%d bytes) failed\n", n ); + mbedtls_fprintf( stderr, "fread(%u bytes) failed\n", n ); goto exit; } @@ -413,7 +413,7 @@ int main( int argc, char *argv[] ) if( fwrite( buffer, 1, n, fout ) != (size_t) n ) { - mbedtls_fprintf( stderr, "fwrite(%d bytes) failed\n", n ); + mbedtls_fprintf( stderr, "fwrite(%u bytes) failed\n", n ); goto exit; } } diff --git a/programs/aes/crypt_and_hash.c b/programs/aes/crypt_and_hash.c index a5acf5b8b..e2949f25b 100644 --- a/programs/aes/crypt_and_hash.c +++ b/programs/aes/crypt_and_hash.c @@ -219,7 +219,7 @@ int main( int argc, char *argv[] ) p = &argv[6][4]; keylen = 0; - while( sscanf( p, "%02X", &n ) > 0 && + while( sscanf( p, "%02X", (unsigned int*) &n ) > 0 && keylen < (int) sizeof( key ) ) { key[keylen++] = (unsigned char) n; @@ -417,7 +417,7 @@ int main( int argc, char *argv[] ) ( ( filesize - mbedtls_md_get_size( md_info ) ) % mbedtls_cipher_get_block_size( &cipher_ctx ) ) != 0 ) { - mbedtls_fprintf( stderr, "File content not a multiple of the block size (%d).\n", + mbedtls_fprintf( stderr, "File content not a multiple of the block size (%u).\n", mbedtls_cipher_get_block_size( &cipher_ctx )); goto exit; } @@ -484,7 +484,7 @@ int main( int argc, char *argv[] ) if( fread( buffer, 1, ilen, fin ) != ilen ) { - mbedtls_fprintf( stderr, "fread(%d bytes) failed\n", + mbedtls_fprintf( stderr, "fread(%u bytes) failed\n", mbedtls_cipher_get_block_size( &cipher_ctx ) ); goto exit; } diff --git a/programs/pkey/gen_key.c b/programs/pkey/gen_key.c index 23e4e145c..9c1a91c00 100644 --- a/programs/pkey/gen_key.c +++ b/programs/pkey/gen_key.c @@ -302,7 +302,7 @@ int main( int argc, char *argv[] ) NULL, DEV_RANDOM_THRESHOLD, MBEDTLS_ENTROPY_SOURCE_STRONG ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_entropy_add_source returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_entropy_add_source returned -0x%04x\n", (unsigned int) -ret ); goto exit; } @@ -315,7 +315,7 @@ int main( int argc, char *argv[] ) (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%04x\n", (unsigned int) -ret ); goto exit; } @@ -328,7 +328,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_pk_setup( &key, mbedtls_pk_info_from_type( (mbedtls_pk_type_t) opt.type ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_pk_setup returned -0x%04x", -ret ); + mbedtls_printf( " failed\n ! mbedtls_pk_setup returned -0x%04x", (unsigned int) -ret ); goto exit; } @@ -339,7 +339,7 @@ int main( int argc, char *argv[] ) opt.rsa_keysize, 65537 ); if( ret != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_rsa_gen_key returned -0x%04x", -ret ); + mbedtls_printf( " failed\n ! mbedtls_rsa_gen_key returned -0x%04x", (unsigned int) -ret ); goto exit; } } @@ -353,7 +353,7 @@ int main( int argc, char *argv[] ) mbedtls_ctr_drbg_random, &ctr_drbg ); if( ret != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ecp_gen_key returned -0x%04x", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ecp_gen_key returned -0x%04x", (unsigned int) -ret ); goto exit; } } diff --git a/programs/pkey/key_app.c b/programs/pkey/key_app.c index 19dcdfe49..345b7b884 100644 --- a/programs/pkey/key_app.c +++ b/programs/pkey/key_app.c @@ -187,7 +187,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned -0x%04x\n", (unsigned int) -ret ); goto cleanup; } @@ -248,7 +248,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_pk_parse_public_keyfile returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_pk_parse_public_keyfile returned -0x%04x\n", (unsigned int) -ret ); goto cleanup; } diff --git a/programs/pkey/key_app_writer.c b/programs/pkey/key_app_writer.c index 60964292b..937fe9033 100644 --- a/programs/pkey/key_app_writer.c +++ b/programs/pkey/key_app_writer.c @@ -299,7 +299,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); - mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned -0x%04x - %s\n\n", -ret, buf ); + mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -360,7 +360,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); - mbedtls_printf( " failed\n ! mbedtls_pk_parse_public_key returned -0x%04x - %s\n\n", -ret, buf ); + mbedtls_printf( " failed\n ! mbedtls_pk_parse_public_key returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } diff --git a/programs/pkey/pk_decrypt.c b/programs/pkey/pk_decrypt.c index bf425079e..bccfde072 100644 --- a/programs/pkey/pk_decrypt.c +++ b/programs/pkey/pk_decrypt.c @@ -100,7 +100,7 @@ int main( int argc, char *argv[] ) strlen( pers ) ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%04x\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -109,7 +109,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_pk_parse_keyfile( &pk, argv[1], "" ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned -0x%04x\n", (unsigned int) -ret ); goto exit; } @@ -124,7 +124,7 @@ int main( int argc, char *argv[] ) } i = 0; - while( fscanf( f, "%02X", &c ) > 0 && + while( fscanf( f, "%02X", (unsigned int*) &c ) > 0 && i < (int) sizeof( buf ) ) { buf[i++] = (unsigned char) c; @@ -142,7 +142,7 @@ int main( int argc, char *argv[] ) mbedtls_ctr_drbg_random, &ctr_drbg ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_pk_decrypt returned -0x%04x\n", - -ret ); + (unsigned int) -ret ); goto exit; } diff --git a/programs/pkey/pk_encrypt.c b/programs/pkey/pk_encrypt.c index a32b14761..16cd3f0d0 100644 --- a/programs/pkey/pk_encrypt.c +++ b/programs/pkey/pk_encrypt.c @@ -98,7 +98,7 @@ int main( int argc, char *argv[] ) strlen( pers ) ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%04x\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -107,7 +107,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_pk_parse_public_keyfile( &pk, argv[1] ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_pk_parse_public_keyfile returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_pk_parse_public_keyfile returned -0x%04x\n", (unsigned int) -ret ); goto exit; } @@ -130,7 +130,7 @@ int main( int argc, char *argv[] ) mbedtls_ctr_drbg_random, &ctr_drbg ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_pk_encrypt returned -0x%04x\n", - -ret ); + (unsigned int) -ret ); goto exit; } diff --git a/programs/pkey/pk_sign.c b/programs/pkey/pk_sign.c index a354e5b17..4e755c089 100644 --- a/programs/pkey/pk_sign.c +++ b/programs/pkey/pk_sign.c @@ -96,7 +96,7 @@ int main( int argc, char *argv[] ) (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%04x\n", (unsigned int) -ret ); goto exit; } @@ -127,7 +127,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_pk_sign( &pk, MBEDTLS_MD_SHA256, hash, 0, buf, &olen, mbedtls_ctr_drbg_random, &ctr_drbg ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_pk_sign returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_pk_sign returned -0x%04x\n", (unsigned int) -ret ); goto exit; } diff --git a/programs/pkey/pk_verify.c b/programs/pkey/pk_verify.c index 72caf7139..2e0876304 100644 --- a/programs/pkey/pk_verify.c +++ b/programs/pkey/pk_verify.c @@ -86,7 +86,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_pk_parse_public_keyfile( &pk, argv[1] ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_pk_parse_public_keyfile returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_pk_parse_public_keyfile returned -0x%04x\n", (unsigned int) -ret ); goto exit; } @@ -123,7 +123,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_pk_verify( &pk, MBEDTLS_MD_SHA256, hash, 0, buf, i ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_pk_verify returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_pk_verify returned -0x%04x\n", (unsigned int) -ret ); goto exit; } diff --git a/programs/pkey/rsa_decrypt.c b/programs/pkey/rsa_decrypt.c index ff71bd055..3327909b1 100644 --- a/programs/pkey/rsa_decrypt.c +++ b/programs/pkey/rsa_decrypt.c @@ -160,7 +160,7 @@ int main( int argc, char *argv[] ) i = 0; - while( fscanf( f, "%02X", &c ) > 0 && + while( fscanf( f, "%02X", (unsigned int*) &c ) > 0 && i < (int) sizeof( buf ) ) buf[i++] = (unsigned char) c; diff --git a/programs/pkey/rsa_sign.c b/programs/pkey/rsa_sign.c index 9bcd7a627..78ab176f8 100644 --- a/programs/pkey/rsa_sign.c +++ b/programs/pkey/rsa_sign.c @@ -129,7 +129,7 @@ int main( int argc, char *argv[] ) fflush( stdout ); if( ( ret = mbedtls_rsa_check_privkey( &rsa ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_rsa_check_privkey failed with -0x%0x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_rsa_check_privkey failed with -0x%0x\n", (unsigned int) -ret ); goto exit; } @@ -151,7 +151,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_rsa_pkcs1_sign( &rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA256, 20, hash, buf ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_rsa_pkcs1_sign returned -0x%0x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_rsa_pkcs1_sign returned -0x%0x\n\n", (unsigned int) -ret ); goto exit; } diff --git a/programs/pkey/rsa_verify.c b/programs/pkey/rsa_verify.c index 94f0ef9ce..b53177594 100644 --- a/programs/pkey/rsa_verify.c +++ b/programs/pkey/rsa_verify.c @@ -114,7 +114,7 @@ int main( int argc, char *argv[] ) } i = 0; - while( fscanf( f, "%02X", &c ) > 0 && + while( fscanf( f, "%02X", (unsigned int*) &c ) > 0 && i < (int) sizeof( buf ) ) buf[i++] = (unsigned char) c; @@ -144,7 +144,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_rsa_pkcs1_verify( &rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA256, 20, hash, buf ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_rsa_pkcs1_verify returned -0x%0x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_rsa_pkcs1_verify returned -0x%0x\n\n", (unsigned int) -ret ); goto exit; } diff --git a/programs/psa/key_ladder_demo.c b/programs/psa/key_ladder_demo.c index f492e0e5d..1dbbc8145 100644 --- a/programs/psa/key_ladder_demo.c +++ b/programs/psa/key_ladder_demo.c @@ -101,7 +101,7 @@ int main( void ) status = ( expr ); \ if( status != PSA_SUCCESS ) \ { \ - printf( "Error %d at line %u: %s\n", \ + printf( "Error %d at line %d: %s\n", \ (int) status, \ __LINE__, \ #expr ); \ diff --git a/programs/random/gen_entropy.c b/programs/random/gen_entropy.c index 6ae63b725..c60aec966 100644 --- a/programs/random/gen_entropy.c +++ b/programs/random/gen_entropy.c @@ -80,7 +80,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { mbedtls_printf( " failed\n ! mbedtls_entropy_func returned -%04X\n", - ret ); + (unsigned int) ret ); goto cleanup; } diff --git a/programs/ssl/dtls_client.c b/programs/ssl/dtls_client.c index 3ea2a680b..ce1056fa2 100644 --- a/programs/ssl/dtls_client.c +++ b/programs/ssl/dtls_client.c @@ -149,7 +149,7 @@ int main( int argc, char *argv[] ) mbedtls_test_cas_pem_len ); if( ret < 0 ) { - mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -225,7 +225,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -303,7 +303,7 @@ send_request: goto close_notify; default: - mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n\n", -ret ); + mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } } diff --git a/programs/ssl/dtls_server.c b/programs/ssl/dtls_server.c index bb3272478..f63741f25 100644 --- a/programs/ssl/dtls_server.c +++ b/programs/ssl/dtls_server.c @@ -291,7 +291,7 @@ reset: client_ip, cliip_len ) ) != 0 ) { printf( " failed\n ! " - "mbedtls_ssl_set_client_transport_id() returned -0x%x\n\n", -ret ); + "mbedtls_ssl_set_client_transport_id() returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -318,7 +318,7 @@ reset: } else if( ret != 0 ) { - printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret ); + printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", (unsigned int) -ret ); goto reset; } @@ -351,7 +351,7 @@ reset: goto close_notify; default: - printf( " mbedtls_ssl_read returned -0x%x\n\n", -ret ); + printf( " mbedtls_ssl_read returned -0x%x\n\n", (unsigned int) -ret ); goto reset; } } diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c index b723243c9..3724c6411 100644 --- a/programs/ssl/ssl_client1.c +++ b/programs/ssl/ssl_client1.c @@ -134,7 +134,7 @@ int main( void ) mbedtls_test_cas_pem_len ); if( ret < 0 ) { - mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -203,7 +203,7 @@ int main( void ) { if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE ) { - mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } } diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 73a993326..6b09a895a 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -833,7 +833,7 @@ static int ssl_check_record( mbedtls_ssl_context const *ssl, break; default: - mbedtls_printf( "mbedtls_ssl_check_record() failed fatally with -%#04x.\n", -ret ); + mbedtls_printf( "mbedtls_ssl_check_record() failed fatally with -%#04x.\n", (unsigned int) -ret ); return( -1 ); } @@ -1077,7 +1077,7 @@ int report_cid_usage( mbedtls_ssl_context *ssl, if( ret != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_get_peer_cid returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); return( ret ); } @@ -1101,7 +1101,7 @@ int report_cid_usage( mbedtls_ssl_context *ssl, if( ret != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_get_peer_cid returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); return( ret ); } @@ -1111,7 +1111,7 @@ int report_cid_usage( mbedtls_ssl_context *ssl, if( ret != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_get_peer_cid returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); return( ret ); } mbedtls_printf( "(%s) Peer CID (length %u Bytes): ", @@ -2013,7 +2013,7 @@ int main( int argc, char *argv[] ) strlen( pers ) ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -2024,7 +2024,7 @@ int main( int argc, char *argv[] ) strlen( pers ) ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -2082,7 +2082,7 @@ int main( int argc, char *argv[] ) if( ret < 0 ) { mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -2117,7 +2117,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -2142,7 +2142,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { mbedtls_printf( " failed\n ! mbedtls_pk_parse_key returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -2179,7 +2179,7 @@ int main( int argc, char *argv[] ) MBEDTLS_NET_PROTO_TCP : MBEDTLS_NET_PROTO_UDP ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_net_connect returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -2190,7 +2190,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { mbedtls_printf( " failed\n ! net_set_(non)block() returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -2208,7 +2208,7 @@ int main( int argc, char *argv[] ) MBEDTLS_SSL_PRESET_DEFAULT ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_config_defaults returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -2249,7 +2249,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_conf_cid_len returned -%#04x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -2447,7 +2447,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -2527,7 +2527,7 @@ int main( int argc, char *argv[] ) ret != MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS ) { mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n", - -ret ); + (unsigned int) -ret ); if( ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED ) mbedtls_printf( " Unable to verify the server's certificate. " @@ -2599,7 +2599,7 @@ int main( int argc, char *argv[] ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_tls_prf returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -2620,7 +2620,7 @@ int main( int argc, char *argv[] ) sizeof( eap_tls_iv ) ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_tls_prf returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -2667,7 +2667,7 @@ int main( int argc, char *argv[] ) &session_data_len ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_session_saved returned -0x%04x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -2676,7 +2676,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_ssl_get_session( &ssl, &saved_session ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_get_session returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -2827,7 +2827,7 @@ send_request: ret != MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS ) { mbedtls_printf( " failed\n ! mbedtls_ssl_write returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -2955,7 +2955,7 @@ send_request: default: mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -3019,7 +3019,7 @@ send_request: goto close_notify; default: - mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", -ret ); + mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", (unsigned int) -ret ); goto exit; } } @@ -3047,7 +3047,7 @@ send_request: if( ( ret = mbedtls_ssl_session_reset( &ssl ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_session_reset returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -3058,7 +3058,7 @@ send_request: ret != MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS ) { mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -3092,7 +3092,7 @@ send_request: if( ret != MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ) { mbedtls_printf( " failed\n ! mbedtls_ssl_context_save returned " - "-0x%x\n\n", -ret ); + "-0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -3110,7 +3110,7 @@ send_request: buf_len, &buf_len ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_context_save returned " - "-0x%x\n\n", -ret ); + "-0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -3139,7 +3139,7 @@ send_request: context_buf, buf_len ) ) != 0 ) { mbedtls_printf( "failed\n ! mbedtls_base64_encode returned " - "-0x%x\n", -ret ); + "-0x%x\n", (unsigned int) -ret ); mbedtls_free( b64_buf ); goto exit; } @@ -3184,7 +3184,7 @@ send_request: if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned " - "-0x%x\n\n", -ret ); + "-0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -3211,7 +3211,7 @@ send_request: buf_len ) ) != 0 ) { mbedtls_printf( "failed\n ! mbedtls_ssl_context_load returned " - "-0x%x\n\n", -ret ); + "-0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -3283,7 +3283,7 @@ reconnect: if( ( ret = mbedtls_ssl_session_reset( &ssl ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_session_reset returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -3294,7 +3294,7 @@ reconnect: session_data_len ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_session_load returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -3302,7 +3302,7 @@ reconnect: if( ( ret = mbedtls_ssl_set_session( &ssl, &saved_session ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_set_session returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -3312,7 +3312,7 @@ reconnect: MBEDTLS_NET_PROTO_TCP : MBEDTLS_NET_PROTO_UDP ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_net_connect returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -3323,7 +3323,7 @@ reconnect: if( ret != 0 ) { mbedtls_printf( " failed\n ! net_set_(non)block() returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -3334,7 +3334,7 @@ reconnect: ret != MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS ) { mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -3353,7 +3353,7 @@ exit: { char error_buf[100]; mbedtls_strerror( ret, error_buf, 100 ); - mbedtls_printf("Last error was: -0x%X - %s\n\n", -ret, error_buf ); + mbedtls_printf("Last error was: -0x%X - %s\n\n", (unsigned int) -ret, error_buf ); } #endif diff --git a/programs/ssl/ssl_server.c b/programs/ssl/ssl_server.c index 3e1d9a4e6..9668cf93e 100644 --- a/programs/ssl/ssl_server.c +++ b/programs/ssl/ssl_server.c @@ -309,7 +309,7 @@ reset: break; default: - mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", -ret ); + mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", (unsigned int) -ret ); break; } diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index 1d03fe283..ca557caaf 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -932,7 +932,7 @@ static int ssl_check_record( mbedtls_ssl_context const *ssl, break; default: - mbedtls_printf( "mbedtls_ssl_check_record() failed fatally with -%#04x.\n", -ret ); + mbedtls_printf( "mbedtls_ssl_check_record() failed fatally with -%#04x.\n", (unsigned int) -ret ); return( -1 ); } @@ -1720,7 +1720,7 @@ int report_cid_usage( mbedtls_ssl_context *ssl, if( ret != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_get_peer_cid returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); return( ret ); } @@ -2755,7 +2755,7 @@ int main( int argc, char *argv[] ) strlen( pers ) ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -2766,7 +2766,7 @@ int main( int argc, char *argv[] ) strlen( pers ) ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -2823,7 +2823,7 @@ int main( int argc, char *argv[] ) #endif /* MBEDTLS_CERTS_C */ if( ret < 0 ) { - mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -2842,7 +2842,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_x509_crt_parse_file( &srvcert, opt.crt_file ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_file returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -2851,7 +2851,7 @@ int main( int argc, char *argv[] ) key_cert_init++; if( ( ret = mbedtls_pk_parse_keyfile( &pkey, opt.key_file, "" ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } } @@ -2867,7 +2867,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_x509_crt_parse_file( &srvcert2, opt.crt_file2 ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_file(2) returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -2877,7 +2877,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_pk_parse_keyfile( &pkey2, opt.key_file2, "" ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile(2) returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -2904,7 +2904,7 @@ int main( int argc, char *argv[] ) mbedtls_test_srv_crt_rsa_len ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } if( ( ret = mbedtls_pk_parse_key( &pkey, @@ -2912,7 +2912,7 @@ int main( int argc, char *argv[] ) mbedtls_test_srv_key_rsa_len, NULL, 0 ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_pk_parse_key returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } key_cert_init = 2; @@ -2923,7 +2923,7 @@ int main( int argc, char *argv[] ) mbedtls_test_srv_crt_ec_len ) ) != 0 ) { mbedtls_printf( " failed\n ! x509_crt_parse2 returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } if( ( ret = mbedtls_pk_parse_key( &pkey2, @@ -2931,7 +2931,7 @@ int main( int argc, char *argv[] ) mbedtls_test_srv_key_ec_len, NULL, 0 ) ) != 0 ) { mbedtls_printf( " failed\n ! pk_parse_key2 returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } key_cert_init2 = 2; @@ -2951,7 +2951,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_dhm_parse_dhmfile( &dhm, opt.dhm_file ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_dhm_parse_dhmfile returned -0x%04X\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -2988,7 +2988,7 @@ int main( int argc, char *argv[] ) opt.transport == MBEDTLS_SSL_TRANSPORT_STREAM ? MBEDTLS_NET_PROTO_TCP : MBEDTLS_NET_PROTO_UDP ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_net_bind returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_net_bind returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -3005,7 +3005,7 @@ int main( int argc, char *argv[] ) opt.transport, MBEDTLS_SSL_PRESET_DEFAULT ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ssl_config_defaults returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ssl_config_defaults returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -3064,7 +3064,7 @@ int main( int argc, char *argv[] ) if( ret != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_conf_cid_len returned -%#04x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -3390,7 +3390,7 @@ int main( int argc, char *argv[] ) strlen( opt.psk_identity ) ); if( ret != 0 ) { - mbedtls_printf( " failed\n mbedtls_ssl_conf_psk returned -0x%04X\n\n", - ret ); + mbedtls_printf( " failed\n mbedtls_ssl_conf_psk returned -0x%04X\n\n", (unsigned int) -ret ); goto exit; } } @@ -3431,7 +3431,7 @@ int main( int argc, char *argv[] ) #endif if( ret != 0 ) { - mbedtls_printf( " failed\n mbedtls_ssl_conf_dh_param returned -0x%04X\n\n", - ret ); + mbedtls_printf( " failed\n mbedtls_ssl_conf_dh_param returned -0x%04X\n\n", (unsigned int) -ret ); goto exit; } #endif @@ -3444,7 +3444,7 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -3529,7 +3529,7 @@ reset: } #endif - mbedtls_printf( " failed\n ! mbedtls_net_accept returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_net_accept returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -3539,7 +3539,7 @@ reset: ret = mbedtls_net_set_block( &client_fd ); if( ret != 0 ) { - mbedtls_printf( " failed\n ! net_set_(non)block() returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! net_set_(non)block() returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -3552,7 +3552,7 @@ reset: client_ip, cliip_len ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_set_client_transport_id() returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } } @@ -3615,7 +3615,7 @@ handshake: } else if( ret != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", (unsigned int) -ret ); #if defined(MBEDTLS_X509_CRT_PARSE_C) if( ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED ) @@ -3709,7 +3709,7 @@ handshake: != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_tls_prf returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -3730,7 +3730,7 @@ handshake: sizeof( eap_tls_iv ) ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_tls_prf returned -0x%x\n\n", - -ret ); + (unsigned int) -ret ); goto exit; } @@ -3821,7 +3821,7 @@ data_exchange: goto reset; default: - mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", -ret ); + mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", (unsigned int) -ret ); goto reset; } } @@ -3867,7 +3867,7 @@ data_exchange: } larger_buf[ori_len + extra_len] = '\0'; - mbedtls_printf( " %u bytes read (%u + %u)\n\n%s\n", + mbedtls_printf( " %d bytes read (%d + %d)\n\n%s\n", ori_len + extra_len, ori_len, extra_len, (char *) larger_buf ); @@ -3935,7 +3935,7 @@ data_exchange: goto close_notify; default: - mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", -ret ); + mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n", (unsigned int) -ret ); goto reset; } } @@ -4092,7 +4092,7 @@ data_exchange: if( ret != MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ) { mbedtls_printf( " failed\n ! mbedtls_ssl_context_save returned " - "-0x%x\n\n", -ret ); + "-0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -4110,7 +4110,7 @@ data_exchange: buf_len, &buf_len ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_context_save returned " - "-0x%x\n\n", -ret ); + "-0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -4139,7 +4139,7 @@ data_exchange: context_buf, buf_len ) ) != 0 ) { mbedtls_printf( "failed\n ! mbedtls_base64_encode returned " - "-0x%x\n", -ret ); + "-0x%x\n", (unsigned int) -ret ); mbedtls_free( b64_buf ); goto exit; } @@ -4199,7 +4199,7 @@ data_exchange: if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned " - "-0x%x\n\n", -ret ); + "-0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -4232,7 +4232,7 @@ data_exchange: buf_len ) ) != 0 ) { mbedtls_printf( "failed\n ! mbedtls_ssl_context_load returned " - "-0x%x\n\n", -ret ); + "-0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -4275,7 +4275,7 @@ exit: { char error_buf[100]; mbedtls_strerror( ret, error_buf, 100 ); - mbedtls_printf("Last error was: -0x%X - %s\n\n", -ret, error_buf ); + mbedtls_printf("Last error was: -0x%X - %s\n\n", (unsigned int) -ret, error_buf ); } #endif diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c index 57e8e7eba..157593066 100644 --- a/programs/test/benchmark.c +++ b/programs/test/benchmark.c @@ -112,7 +112,7 @@ int main( void ) mbedtls_printf( "FAILED: %s\n", tmp ); #else #define PRINT_ERROR \ - mbedtls_printf( "FAILED: -0x%04x\n", -ret ); + mbedtls_printf( "FAILED: -0x%04x\n", (unsigned int) -ret ); #endif #define TIME_AND_TSC( TITLE, CODE ) \ diff --git a/programs/test/udp_proxy.c b/programs/test/udp_proxy.c index 7447571f4..d601dcc69 100644 --- a/programs/test/udp_proxy.c +++ b/programs/test/udp_proxy.c @@ -456,7 +456,7 @@ static int ctx_buffer_append( ctx_buffer *buf, { if( ( ret = ctx_buffer_flush( buf ) ) <= 0 ) { - mbedtls_printf( "ctx_buffer_flush failed with -%#04x", -ret ); + mbedtls_printf( "ctx_buffer_flush failed with -%#04x", (unsigned int) -ret ); return( ret ); } } @@ -495,7 +495,7 @@ static int dispatch_data( mbedtls_net_context *ctx, ret = mbedtls_net_send( ctx, data, len ); if( ret < 0 ) { - mbedtls_printf( "net_send returned -%#04x\n", -ret ); + mbedtls_printf( "net_send returned -%#04x\n", (unsigned int) -ret ); } return( ret ); } @@ -999,7 +999,7 @@ exit: { char error_buf[100]; mbedtls_strerror( ret, error_buf, 100 ); - mbedtls_printf( "Last error was: -0x%04X - %s\n\n", - ret, error_buf ); + mbedtls_printf( "Last error was: -0x%04X - %s\n\n", (unsigned int) -ret, error_buf ); fflush( stdout ); } #endif diff --git a/programs/util/strerror.c b/programs/util/strerror.c index 458280c98..b0487c08e 100644 --- a/programs/util/strerror.c +++ b/programs/util/strerror.c @@ -79,7 +79,7 @@ int main( int argc, char *argv[] ) { char error_buf[200]; mbedtls_strerror( val, error_buf, 200 ); - mbedtls_printf("Last error was: -0x%04x - %s\n\n", (int) -val, error_buf ); + mbedtls_printf("Last error was: -0x%04x - %s\n\n", (unsigned int) -val, error_buf ); } #if defined(_WIN32) diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c index 432eefbf7..7723a372e 100644 --- a/programs/x509/cert_app.c +++ b/programs/x509/cert_app.c @@ -258,7 +258,7 @@ int main( int argc, char *argv[] ) { if( ( ret = mbedtls_x509_crt_parse_path( &cacert, opt.ca_path ) ) < 0 ) { - mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_path returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_path returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -268,7 +268,7 @@ int main( int argc, char *argv[] ) { if( ( ret = mbedtls_x509_crt_parse_file( &cacert, opt.ca_file ) ) < 0 ) { - mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_file returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_file returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } @@ -282,7 +282,7 @@ int main( int argc, char *argv[] ) { if( ( ret = mbedtls_x509_crl_parse_file( &cacrl, opt.crl_file ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_x509_crl_parse returned -0x%x\n\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_x509_crl_parse returned -0x%x\n\n", (unsigned int) -ret ); goto exit; } diff --git a/programs/x509/cert_write.c b/programs/x509/cert_write.c index d36d73c0d..9a7dc591d 100644 --- a/programs/x509/cert_write.c +++ b/programs/x509/cert_write.c @@ -507,7 +507,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_mpi_read_string " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -527,7 +527,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_file " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -537,7 +537,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_x509_dn_gets " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -561,7 +561,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_x509_csr_parse_file " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -571,7 +571,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_x509_dn_gets " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -596,7 +596,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -612,7 +612,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile " - "returned -x%02x - %s\n\n", -ret, buf ); + "returned -x%02x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -646,7 +646,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_subject_name " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -654,7 +654,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_issuer_name " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -669,7 +669,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_serial " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -678,7 +678,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_validity " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -696,7 +696,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! x509write_crt_set_basic_contraints " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -716,7 +716,7 @@ int main( int argc, char *argv[] ) mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_subject" "_key_identifier returned -0x%04x - %s\n\n", - -ret, buf ); + (unsigned int) -ret, buf ); goto exit; } @@ -735,7 +735,7 @@ int main( int argc, char *argv[] ) mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_authority_" "key_identifier returned -0x%04x - %s\n\n", - -ret, buf ); + (unsigned int) -ret, buf ); goto exit; } @@ -754,7 +754,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_key_usage " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -772,7 +772,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! mbedtls_x509write_crt_set_ns_cert_type " - "returned -0x%04x - %s\n\n", -ret, buf ); + "returned -0x%04x - %s\n\n", (unsigned int) -ret, buf ); goto exit; } @@ -790,7 +790,7 @@ int main( int argc, char *argv[] ) { mbedtls_strerror( ret, buf, 1024 ); mbedtls_printf( " failed\n ! write_certificate -0x%04x - %s\n\n", - -ret, buf ); + (unsigned int) -ret, buf ); goto exit; } diff --git a/scripts/data_files/error.fmt b/scripts/data_files/error.fmt index 0e128e84f..97b74bcd9 100644 --- a/scripts/data_files/error.fmt +++ b/scripts/data_files/error.fmt @@ -113,7 +113,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) high_level_error_description = mbedtls_high_level_strerr( ret ); if( high_level_error_description == NULL ) - mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret ); + mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret ); else mbedtls_snprintf( buf, buflen, "%s", high_level_error_description ); @@ -150,7 +150,7 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen ) low_level_error_description = mbedtls_low_level_strerr( ret ); if( low_level_error_description == NULL ) - mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", use_ret ); + mbedtls_snprintf( buf, buflen, "UNKNOWN ERROR CODE (%04X)", (unsigned int) use_ret ); else mbedtls_snprintf( buf, buflen, "%s", low_level_error_description ); } diff --git a/tests/suites/test_suite_version.function b/tests/suites/test_suite_version.function index 10f9e1154..7d59794bd 100644 --- a/tests/suites/test_suite_version.function +++ b/tests/suites/test_suite_version.function @@ -52,7 +52,7 @@ void check_runtime_version( char * version_str ) mbedtls_version_get_string( get_str ); mbedtls_version_get_string_full( get_str_full ); - mbedtls_snprintf( build_str, 100, "%d.%d.%d", + mbedtls_snprintf( build_str, 100, "%u.%u.%u", (get_int >> 24) & 0xFF, (get_int >> 16) & 0xFF, (get_int >> 8) & 0xFF ); diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function index 85ff41df2..f3e83d69e 100644 --- a/tests/suites/test_suite_x509parse.function +++ b/tests/suites/test_suite_x509parse.function @@ -237,7 +237,7 @@ int verify_parse_san( mbedtls_x509_subject_alternative_name *san, char *p = *buf; size_t n = *size; - ret = mbedtls_snprintf( p, n, "type : %u", san->type ); + ret = mbedtls_snprintf( p, n, "type : %d", san->type ); MBEDTLS_X509_SAFE_SNPRINTF; switch( san->type )