altcp_tls_mbedtls_mem: fix compiling for sizeof(mem_size_t) < sizeof(size_t)

This commit is contained in:
goldsimon 2017-03-23 12:15:54 +01:00
parent d71653f049
commit 1ddb125e2c

View File

@ -188,7 +188,13 @@ altcp_mbedtls_free(void *conf, altcp_mbedtls_state_t *state)
void * void *
altcp_mbedtls_alloc_config(size_t size) altcp_mbedtls_alloc_config(size_t size)
{ {
void *ret = (altcp_mbedtls_state_t *)mem_malloc(size); void *ret;
size_t checked_size = (mem_size_t)size;
if (size != checked_size) {
/* allocation too big (mem_size_t overflow) */
return NULL;
}
ret = (altcp_mbedtls_state_t *)mem_malloc((mem_size_t)size);
if (ret != NULL) { if (ret != NULL) {
memset(ret, 0, size); memset(ret, 0, size);
} }