Check additional return values in some test cases

This commit is contained in:
Paul Bakker 2014-04-17 16:08:20 +02:00
parent 94b916c7b5
commit 8a0c0a9ed9
3 changed files with 13 additions and 3 deletions

View file

@ -146,7 +146,12 @@ int main( int argc, char *argv[] )
printf( " failed\n ! fopen returned NULL\n" );
goto exit;
}
fgets( buf, sizeof(buf), f );
if( fgets( buf, sizeof(buf), f ) == NULL )
{
fclose( f );
printf( "Error: fgets() failed to retrieve password\n" );
goto exit;
}
fclose( f );
i = (int) strlen( buf );

View file

@ -101,6 +101,7 @@ void mpi_read_file( int radix_X, char *input_file, char *input_A,
mpi_init( &X );
file = fopen( input_file, "r" );
TEST_ASSERT( file != NULL );
TEST_ASSERT( mpi_read_file( &X, radix_X, file ) == result );
fclose(file);

View file

@ -17,6 +17,7 @@ void pk_write_pubkey_check( char *key_file )
unsigned char check_buf[5000];
int ret;
FILE *f;
size_t ilen;
memset( buf, 0, sizeof( buf ) );
memset( check_buf, 0, sizeof( check_buf ) );
@ -29,9 +30,10 @@ void pk_write_pubkey_check( char *key_file )
f = fopen( key_file, "r" );
TEST_ASSERT( f != NULL );
fread( check_buf, 1, sizeof( check_buf ) - 1, f );
ilen = fread( check_buf, 1, sizeof( check_buf ) - 1, f );
fclose( f );
TEST_ASSERT( ilen == strlen( (char *) buf ) );
TEST_ASSERT( strncmp( (char *) buf, (char *) check_buf, sizeof( buf ) ) == 0 );
pk_free( &key );
@ -46,6 +48,7 @@ void pk_write_key_check( char *key_file )
unsigned char check_buf[5000];
int ret;
FILE *f;
size_t ilen;
memset( buf, 0, sizeof( buf ) );
memset( check_buf, 0, sizeof( check_buf ) );
@ -58,9 +61,10 @@ void pk_write_key_check( char *key_file )
f = fopen( key_file, "r" );
TEST_ASSERT( f != NULL );
fread( check_buf, 1, sizeof( check_buf ) - 1, f );
ilen = fread( check_buf, 1, sizeof( check_buf ) - 1, f );
fclose( f );
TEST_ASSERT( ilen == strlen( (char *) buf ) );
TEST_ASSERT( strncmp( (char *) buf, (char *) check_buf, sizeof( buf ) ) == 0 );
pk_free( &key );