mirror of
				https://github.com/Mbed-TLS/mbedtls.git
				synced 2025-10-31 21:50:31 +03:00 
			
		
		
		
	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>
This commit is contained in:
		| @@ -137,7 +137,7 @@ int mbedtls_test_ssl_buffer_put(mbedtls_test_ssl_buffer *buf, | ||||
|     } | ||||
|  | ||||
|     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 @@ int mbedtls_test_ssl_buffer_get(mbedtls_test_ssl_buffer *buf, | ||||
|     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 @@ int mbedtls_test_ssl_message_queue_setup( | ||||
|         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 @@ int mbedtls_test_ssl_message_queue_push_info( | ||||
|     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 @@ int mbedtls_test_ssl_message_queue_pop_info( | ||||
|         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 @@ int mbedtls_test_mock_tcp_recv_msg(void *ctx, | ||||
|     } | ||||
|     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 @@ int mbedtls_test_ssl_build_transforms(mbedtls_ssl_transform *t_in, | ||||
| #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 @@ int mbedtls_test_ssl_build_transforms(mbedtls_ssl_transform *t_in, | ||||
|     /* 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: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user