Fix issue of conversion from size_t to int

ssl_helpers.c is treated with W3 warning level in MSVC complier.
So that it's reported as error for warning of conversion from
size_t to int. This change fixes all this type of warning seen in
Microsoft Visual Studio 12.0. Besides, some potential problems of
type conversion are also handled.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
diff --git a/tests/src/test_helpers/ssl_helpers.c b/tests/src/test_helpers/ssl_helpers.c
index c7e6304..b7a7e86 100644
--- a/tests/src/test_helpers/ssl_helpers.c
+++ b/tests/src/test_helpers/ssl_helpers.c
@@ -137,7 +137,7 @@
     }
 
     buf->content_length += input_len;
-    return input_len;
+    return (input_len > INT_MAX) ? INT_MAX : (int) input_len;
 }
 
 int mbedtls_test_ssl_buffer_get(mbedtls_test_ssl_buffer *buf,
@@ -171,7 +171,7 @@
     buf->content_length -= output_len;
     buf->start = (buf->start + output_len) % buf->capacity;
 
-    return output_len;
+    return (output_len > INT_MAX) ? INT_MAX : (int) output_len;
 }
 
 int mbedtls_test_ssl_message_queue_setup(
@@ -182,7 +182,7 @@
         return MBEDTLS_ERR_SSL_ALLOC_FAILED;
     }
 
-    queue->capacity = capacity;
+    queue->capacity = (capacity > INT_MAX) ? INT_MAX : (int) capacity;
     queue->pos = 0;
     queue->num = 0;
 
@@ -218,7 +218,7 @@
     place = (queue->pos + queue->num) % queue->capacity;
     queue->messages[place] = len;
     queue->num++;
-    return len;
+    return (len > INT_MAX) ? INT_MAX : (int) len;
 }
 
 int mbedtls_test_ssl_message_queue_pop_info(
@@ -241,7 +241,8 @@
         queue->pos += queue->capacity;
     }
 
-    return (message_length > buf_len) ? buf_len : message_length;
+    return (message_length > INT_MAX && buf_len > INT_MAX) ? INT_MAX :
+           (message_length > buf_len) ? (int) buf_len : (int) message_length;
 }
 
 /*
@@ -513,7 +514,7 @@
     }
     mbedtls_test_ssl_message_queue_pop_info(queue, buf_len);
 
-    return msg_len;
+    return (msg_len > INT_MAX) ? INT_MAX : (int) msg_len;
 }
 
 #if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) && \
@@ -990,13 +991,21 @@
 #endif /* MBEDTLS_CIPHER_MODE_CBC */
 
     CHK(mbedtls_cipher_setkey(&t_in->cipher_ctx_enc, key0,
-                              keylen << 3, MBEDTLS_ENCRYPT) == 0);
+                              (keylen << 3 > INT_MAX) ? INT_MAX : (int) keylen << 3,
+                              MBEDTLS_ENCRYPT)
+        == 0);
     CHK(mbedtls_cipher_setkey(&t_in->cipher_ctx_dec, key1,
-                              keylen << 3, MBEDTLS_DECRYPT) == 0);
+                              (keylen << 3 > INT_MAX) ? INT_MAX : (int) keylen << 3,
+                              MBEDTLS_DECRYPT)
+        == 0);
     CHK(mbedtls_cipher_setkey(&t_out->cipher_ctx_enc, key1,
-                              keylen << 3, MBEDTLS_ENCRYPT) == 0);
+                              (keylen << 3 > INT_MAX) ? INT_MAX : (int) keylen << 3,
+                              MBEDTLS_ENCRYPT)
+        == 0);
     CHK(mbedtls_cipher_setkey(&t_out->cipher_ctx_dec, key0,
-                              keylen << 3, MBEDTLS_DECRYPT) == 0);
+                              (keylen << 3 > INT_MAX) ? INT_MAX : (int) keylen << 3,
+                              MBEDTLS_DECRYPT)
+        == 0);
 
     /* Setup MAC contexts */
 #if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC)
@@ -1154,12 +1163,12 @@
     /* Add CID */
     memcpy(&t_in->in_cid,  cid0, cid0_len);
     memcpy(&t_in->out_cid, cid1, cid1_len);
-    t_in->in_cid_len = cid0_len;
-    t_in->out_cid_len = cid1_len;
+    t_in->in_cid_len = (uint8_t) cid0_len;
+    t_in->out_cid_len = (uint8_t) cid1_len;
     memcpy(&t_out->in_cid,  cid1, cid1_len);
     memcpy(&t_out->out_cid, cid0, cid0_len);
-    t_out->in_cid_len = cid1_len;
-    t_out->out_cid_len = cid0_len;
+    t_out->in_cid_len = (uint8_t) cid1_len;
+    t_out->out_cid_len = (uint8_t) cid0_len;
 #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
 
 cleanup: