Fix small issues in tests found by Coverity
diff --git a/tests/suites/test_suite_cipher.function b/tests/suites/test_suite_cipher.function
index 30f154c..967a6a0 100644
--- a/tests/suites/test_suite_cipher.function
+++ b/tests/suites/test_suite_cipher.function
@@ -95,7 +95,7 @@
 void enc_dec_buf( int cipher_id, char *cipher_string, int key_len,
                   int length_val, int pad_mode )
 {
-    size_t length = length_val, outlen, total_len, i;
+    size_t length = length_val, outlen, total_len, i, block_size;
     unsigned char key[32];
     unsigned char iv[16];
     unsigned char ad[13];
@@ -162,14 +162,17 @@
     TEST_ASSERT( 0 == mbedtls_cipher_update_ad( &ctx_enc, ad, sizeof( ad ) - i ) );
 #endif
 
+    block_size = mbedtls_cipher_get_block_size( &ctx_enc );
+    TEST_ASSERT( block_size != 0 );
+
     /* encode length number of bytes from inbuf */
     TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx_enc, inbuf, length, encbuf, &outlen ) );
     total_len = outlen;
 
     TEST_ASSERT( total_len == length ||
-                 ( total_len % mbedtls_cipher_get_block_size( &ctx_enc ) == 0 &&
+                 ( total_len % block_size == 0 &&
                    total_len < length &&
-                   total_len + mbedtls_cipher_get_block_size( &ctx_enc ) > length ) );
+                   total_len + block_size > length ) );
 
     TEST_ASSERT( 0 == mbedtls_cipher_finish( &ctx_enc, encbuf + outlen, &outlen ) );
     total_len += outlen;
@@ -179,18 +182,18 @@
 #endif
 
     TEST_ASSERT( total_len == length ||
-                 ( total_len % mbedtls_cipher_get_block_size( &ctx_enc ) == 0 &&
+                 ( total_len % block_size == 0 &&
                    total_len > length &&
-                   total_len <= length + mbedtls_cipher_get_block_size( &ctx_enc ) ) );
+                   total_len <= length + block_size ) );
 
     /* decode the previously encoded string */
     TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx_dec, encbuf, total_len, decbuf, &outlen ) );
     total_len = outlen;
 
     TEST_ASSERT( total_len == length ||
-                 ( total_len % mbedtls_cipher_get_block_size( &ctx_dec ) == 0 &&
+                 ( total_len % block_size == 0 &&
                    total_len < length &&
-                   total_len + mbedtls_cipher_get_block_size( &ctx_dec ) >= length ) );
+                   total_len + block_size >= length ) );
 
     TEST_ASSERT( 0 == mbedtls_cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
     total_len += outlen;
@@ -322,6 +325,7 @@
     size_t first_length = first_length_val;
     size_t second_length = second_length_val;
     size_t length = first_length + second_length;
+    size_t block_size;
     unsigned char key[32];
     unsigned char iv[16];
 
@@ -367,31 +371,34 @@
     TEST_ASSERT( 0 == mbedtls_cipher_update_ad( &ctx_enc, NULL, 0 ) );
 #endif
 
+    block_size = mbedtls_cipher_get_block_size( &ctx_enc );
+    TEST_ASSERT( block_size != 0 );
+
     /* encode length number of bytes from inbuf */
     TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx_enc, inbuf, first_length, encbuf, &outlen ) );
     totaloutlen = outlen;
     TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx_enc, inbuf + first_length, second_length, encbuf + totaloutlen, &outlen ) );
     totaloutlen += outlen;
     TEST_ASSERT( totaloutlen == length ||
-                 ( totaloutlen % mbedtls_cipher_get_block_size( &ctx_enc ) == 0 &&
+                 ( totaloutlen % block_size == 0 &&
                    totaloutlen < length &&
-                   totaloutlen + mbedtls_cipher_get_block_size( &ctx_enc ) > length ) );
+                   totaloutlen + block_size > length ) );
 
     TEST_ASSERT( 0 == mbedtls_cipher_finish( &ctx_enc, encbuf + totaloutlen, &outlen ) );
     totaloutlen += outlen;
     TEST_ASSERT( totaloutlen == length ||
-                 ( totaloutlen % mbedtls_cipher_get_block_size( &ctx_enc ) == 0 &&
+                 ( totaloutlen % block_size == 0 &&
                    totaloutlen > length &&
-                   totaloutlen <= length + mbedtls_cipher_get_block_size( &ctx_enc ) ) );
+                   totaloutlen <= length + block_size ) );
 
     /* decode the previously encoded string */
     TEST_ASSERT( 0 == mbedtls_cipher_update( &ctx_dec, encbuf, totaloutlen, decbuf, &outlen ) );
     totaloutlen = outlen;
 
     TEST_ASSERT( totaloutlen == length ||
-                 ( totaloutlen % mbedtls_cipher_get_block_size( &ctx_dec ) == 0 &&
+                 ( totaloutlen % block_size == 0 &&
                    totaloutlen < length &&
-                   totaloutlen + mbedtls_cipher_get_block_size( &ctx_dec ) >= length ) );
+                   totaloutlen + block_size >= length ) );
 
     TEST_ASSERT( 0 == mbedtls_cipher_finish( &ctx_dec, decbuf + outlen, &outlen ) );
     totaloutlen += outlen;
diff --git a/tests/suites/test_suite_md.function b/tests/suites/test_suite_md.function
index 099d109..0fcaa38 100644
--- a/tests/suites/test_suite_md.function
+++ b/tests/suites/test_suite_md.function
@@ -359,7 +359,7 @@
     md_info = mbedtls_md_info_from_string( md_name );
     TEST_ASSERT( md_info != NULL );
 
-    mbedtls_md_file( md_info, filename, output);
+    TEST_ASSERT( mbedtls_md_file( md_info, filename, output ) == 0 );
     hexify( hash_str, output, mbedtls_md_get_size(md_info) );
 
     TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function
index 1308e56..72b4940 100644
--- a/tests/suites/test_suite_mpi.function
+++ b/tests/suites/test_suite_mpi.function
@@ -150,6 +150,7 @@
 {
     mbedtls_mpi X, Y;
     FILE *file_out, *file_in;
+    int ret;
 
     mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y );
 
@@ -157,13 +158,15 @@
 
     file_out = fopen( output_file, "w" );
     TEST_ASSERT( file_out != NULL );
-    TEST_ASSERT( mbedtls_mpi_write_file( NULL, &X, output_radix, file_out ) == 0 );
+    ret = mbedtls_mpi_write_file( NULL, &X, output_radix, file_out );
     fclose(file_out);
+    TEST_ASSERT( ret == 0 );
 
     file_in = fopen( output_file, "r" );
     TEST_ASSERT( file_in != NULL );
-    TEST_ASSERT( mbedtls_mpi_read_file( &Y, output_radix, file_in ) == 0 );
+    ret = mbedtls_mpi_read_file( &Y, output_radix, file_in );
     fclose(file_in);
+    TEST_ASSERT( ret == 0 );
 
     TEST_ASSERT( mbedtls_mpi_cmp_mpi( &X, &Y ) == 0 );
 
diff --git a/tests/suites/test_suite_pkcs5.function b/tests/suites/test_suite_pkcs5.function
index 41531ad..ab53326 100644
--- a/tests/suites/test_suite_pkcs5.function
+++ b/tests/suites/test_suite_pkcs5.function
@@ -34,8 +34,6 @@
 
     info = mbedtls_md_info_from_type( hash );
     TEST_ASSERT( info != NULL );
-    if( info == NULL )
-        return;
     TEST_ASSERT( mbedtls_md_setup( &ctx, info, 1 ) == 0 );
     TEST_ASSERT( mbedtls_pkcs5_pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
                                      it_cnt, key_len, key ) == 0 );
diff --git a/tests/suites/test_suite_x509write.function b/tests/suites/test_suite_x509write.function
index 789ddbc..356af75 100644
--- a/tests/suites/test_suite_x509write.function
+++ b/tests/suites/test_suite_x509write.function
@@ -119,8 +119,8 @@
     f = fopen( cert_check_file, "r" );
     TEST_ASSERT( f != NULL );
     olen = fread( check_buf, 1, sizeof(check_buf), f );
-    TEST_ASSERT( olen < sizeof(check_buf) );
     fclose( f );
+    TEST_ASSERT( olen < sizeof(check_buf) );
 
     TEST_ASSERT( olen >= pem_len - 1 );
     TEST_ASSERT( memcmp( buf, check_buf, pem_len - 1 ) == 0 );