Fix -Wshadow warnings

Checked that it is supported by gcc 4.2.1 (FreeBSD 9).

fixes #240
This commit is contained in:
Manuel Pégourié-Gonnard 2015-08-27 12:02:40 +02:00
parent 4d04cdcd12
commit ea35666f50
7 changed files with 28 additions and 29 deletions

View file

@ -25,7 +25,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
# note: starting with CMake 2.8 we could use CMAKE_C_COMPILER_VERSION # note: starting with CMake 2.8 we could use CMAKE_C_COMPILER_VERSION
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
OUTPUT_VARIABLE GCC_VERSION) OUTPUT_VARIABLE GCC_VERSION)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wshadow")
if (GCC_VERSION VERSION_GREATER 4.5 OR GCC_VERSION VERSION_EQUAL 4.5) if (GCC_VERSION VERSION_GREATER 4.5 OR GCC_VERSION VERSION_EQUAL 4.5)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wlogical-op")
endif() endif()
@ -39,7 +39,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
endif(CMAKE_COMPILER_IS_GNUCC) endif(CMAKE_COMPILER_IS_GNUCC)
if(CMAKE_COMPILER_IS_CLANG) if(CMAKE_COMPILER_IS_CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -W -Wdeclaration-after-statement -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow")
set(CMAKE_C_FLAGS_RELEASE "-O2") set(CMAKE_C_FLAGS_RELEASE "-O2")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3") set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage") set(CMAKE_C_FLAGS_COVERAGE "-O0 -g3 --coverage")

View file

@ -29,6 +29,7 @@ Bugfix
* Fix bug in mbedtls_rsa_public() and mbedtls_rsa_private() that could * Fix bug in mbedtls_rsa_public() and mbedtls_rsa_private() that could
result trying to unlock an unlocked mutex on invalid input (found by result trying to unlock an unlocked mutex on invalid input (found by
Fredrik Axelsson) (#257) Fredrik Axelsson) (#257)
* Fix -Wshadow warnings (found by hnrkp) (#240)
Changes Changes
* The PEM parser now accepts a trailing space at end of lines (#226). * The PEM parser now accepts a trailing space at end of lines (#226).

View file

@ -140,7 +140,7 @@ int mbedtls_platform_entropy_poll( void *data,
unsigned char *output, size_t len, size_t *olen ) unsigned char *output, size_t len, size_t *olen )
{ {
FILE *file; FILE *file;
size_t ret; size_t read_len;
((void) data); ((void) data);
#if defined(HAVE_GETRANDOM) #if defined(HAVE_GETRANDOM)
@ -165,8 +165,8 @@ int mbedtls_platform_entropy_poll( void *data,
if( file == NULL ) if( file == NULL )
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
ret = fread( output, 1, len, file ); read_len = fread( output, 1, len, file );
if( ret != len ) if( read_len != len )
{ {
fclose( file ); fclose( file );
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );

View file

@ -694,8 +694,6 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl )
} }
else else
{ {
int ret;
/* Initialize HMAC contexts */ /* Initialize HMAC contexts */
if( ( ret = mbedtls_md_setup( &transform->md_ctx_enc, md_info, 1 ) ) != 0 || if( ( ret = mbedtls_md_setup( &transform->md_ctx_enc, md_info, 1 ) ) != 0 ||
( ret = mbedtls_md_setup( &transform->md_ctx_dec, md_info, 1 ) ) != 0 ) ( ret = mbedtls_md_setup( &transform->md_ctx_dec, md_info, 1 ) ) != 0 )
@ -1455,7 +1453,7 @@ static int ssl_encrypt_buf( mbedtls_ssl_context *ssl )
/* /*
* Generate IV * Generate IV
*/ */
int ret = ssl->conf->f_rng( ssl->conf->p_rng, ssl->transform_out->iv_enc, ret = ssl->conf->f_rng( ssl->conf->p_rng, ssl->transform_out->iv_enc,
ssl->transform_out->ivlen ); ssl->transform_out->ivlen );
if( ret != 0 ) if( ret != 0 )
return( ret ); return( ret );

View file

@ -1925,7 +1925,7 @@ reset:
if( ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED ) if( ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED )
{ {
char vrfy_buf[512]; char vrfy_buf[512];
uint32_t flags = mbedtls_ssl_get_verify_result( &ssl ); flags = mbedtls_ssl_get_verify_result( &ssl );
mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), " ! ", flags ); mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), " ! ", flags );

View file

@ -108,26 +108,26 @@ int main( void )
#define TIME_AND_TSC( TITLE, CODE ) \ #define TIME_AND_TSC( TITLE, CODE ) \
do { \ do { \
unsigned long i, j, tsc; \ unsigned long ii, jj, tsc; \
\ \
mbedtls_printf( HEADER_FORMAT, TITLE ); \ mbedtls_printf( HEADER_FORMAT, TITLE ); \
fflush( stdout ); \ fflush( stdout ); \
\ \
mbedtls_set_alarm( 1 ); \ mbedtls_set_alarm( 1 ); \
for( i = 1; ! mbedtls_timing_alarmed; i++ ) \ for( ii = 1; ! mbedtls_timing_alarmed; ii++ ) \
{ \ { \
CODE; \ CODE; \
} \ } \
\ \
tsc = mbedtls_timing_hardclock(); \ tsc = mbedtls_timing_hardclock(); \
for( j = 0; j < 1024; j++ ) \ for( jj = 0; jj < 1024; jj++ ) \
{ \ { \
CODE; \ CODE; \
} \ } \
\ \
mbedtls_printf( "%9lu Kb/s, %9lu cycles/byte\n", \ mbedtls_printf( "%9lu Kb/s, %9lu cycles/byte\n", \
i * BUFSIZE / 1024, \ ii * BUFSIZE / 1024, \
( mbedtls_timing_hardclock() - tsc ) / ( j * BUFSIZE ) ); \ ( mbedtls_timing_hardclock() - tsc ) / ( jj * BUFSIZE ) ); \
} while( 0 ) } while( 0 )
#if defined(MBEDTLS_ERROR_C) #if defined(MBEDTLS_ERROR_C)
@ -149,7 +149,7 @@ do { \
#define MEMORY_MEASURE_PRINT( title_len ) \ #define MEMORY_MEASURE_PRINT( title_len ) \
mbedtls_memory_buffer_alloc_max_get( &max_used, &max_blocks ); \ mbedtls_memory_buffer_alloc_max_get( &max_used, &max_blocks ); \
for( i = 12 - title_len; i != 0; i-- ) mbedtls_printf( " " ); \ for( ii = 12 - title_len; ii != 0; ii-- ) mbedtls_printf( " " ); \
max_used -= prv_used; \ max_used -= prv_used; \
max_blocks -= prv_blocks; \ max_blocks -= prv_blocks; \
max_bytes = max_used + MEM_BLOCK_OVERHEAD * max_blocks; \ max_bytes = max_used + MEM_BLOCK_OVERHEAD * max_blocks; \
@ -162,7 +162,7 @@ do { \
#define TIME_PUBLIC( TITLE, TYPE, CODE ) \ #define TIME_PUBLIC( TITLE, TYPE, CODE ) \
do { \ do { \
unsigned long i; \ unsigned long ii; \
int ret; \ int ret; \
MEMORY_MEASURE_INIT; \ MEMORY_MEASURE_INIT; \
\ \
@ -171,7 +171,7 @@ do { \
mbedtls_set_alarm( 3 ); \ mbedtls_set_alarm( 3 ); \
\ \
ret = 0; \ ret = 0; \
for( i = 1; ! mbedtls_timing_alarmed && ! ret ; i++ ) \ for( ii = 1; ! mbedtls_timing_alarmed && ! ret ; ii++ ) \
{ \ { \
CODE; \ CODE; \
} \ } \
@ -182,7 +182,7 @@ do { \
} \ } \
else \ else \
{ \ { \
mbedtls_printf( "%6lu " TYPE "/s", i / 3 ); \ mbedtls_printf( "%6lu " TYPE "/s", ii / 3 ); \
MEMORY_MEASURE_PRINT( sizeof( TYPE ) + 1 ); \ MEMORY_MEASURE_PRINT( sizeof( TYPE ) + 1 ); \
mbedtls_printf( "\n" ); \ mbedtls_printf( "\n" ); \
} \ } \

View file

@ -389,7 +389,7 @@ void update_dropped( const packet *p )
while( cur < end ) while( cur < end )
{ {
size_t len = ( ( cur[11] << 8 ) | cur[12] ) + 13; len = ( ( cur[11] << 8 ) | cur[12] ) + 13;
id = len % sizeof( dropped ); id = len % sizeof( dropped );
++dropped[id]; ++dropped[id];