fix: fix misra violations

Fix misra violations reported by cppcheck

Change-Id: I9ba032f393db9aa175273e98cdc6ff7c83605422
Signed-off-by: Shruti Gupta <shruti.gupta@arm.com>
diff --git a/lib/allocator/src/memory_alloc.c b/lib/allocator/src/memory_alloc.c
index 6af6cb1..9a0a9f1 100644
--- a/lib/allocator/src/memory_alloc.c
+++ b/lib/allocator/src/memory_alloc.c
@@ -93,11 +93,11 @@
 		return 1;
 	}
 
-	if (hdr->prev != NULL && hdr->prev == hdr->next) {
+	if ((hdr->prev != NULL) && (hdr->prev == hdr->next)) {
 		return 1;
 	}
 
-	if (hdr->prev_free != NULL && hdr->prev_free == hdr->next_free)	{
+	if ((hdr->prev_free != NULL) && (hdr->prev_free == hdr->next_free))	{
 		return 1;
 	}
 
@@ -109,7 +109,7 @@
 	struct memory_header_s *prv = heap->first;
 	struct memory_header_s *cur;
 
-	if (prv == NULL || verify_header(prv) != 0) {
+	if ((prv == NULL) || (verify_header(prv) != 0)) {
 		return 1;
 	}
 
@@ -143,17 +143,19 @@
 	struct memory_header_s *cur = heap->first_free;
 	unsigned char *p;
 	void *ret;
-	size_t original_len, len;
+	size_t original_len;
+	size_t len;
 
-	if (heap->buf == NULL || heap->first == NULL) {
+	if ((heap->buf == NULL) || (heap->first == NULL)) {
 		return NULL;
 	}
 
-	original_len = len = n * size;
+	original_len = n * size;
+	len = original_len;
 
-	if (n == 0UL || size == 0UL || len / n != size) {
+	if ((n == 0UL) || (size == 0UL) || ((len / n) != size)) {
 		return NULL;
-	} else if (len > (size_t)-MBEDTLS_MEMORY_ALIGN_MULTIPLE) {
+	} else if (len > ((size_t)-MBEDTLS_MEMORY_ALIGN_MULTIPLE)) {
 		return NULL;
 	}
 
@@ -197,12 +199,12 @@
 		cur->prev_free = NULL;
 		cur->next_free = NULL;
 
-		if (heap->verify & MBEDTLS_MEMORY_VERIFY_ALLOC) {
+		if ((heap->verify & MBEDTLS_MEMORY_VERIFY_ALLOC) != 0) {
 			assert(verify_chain(heap) == 0);
 		}
 
 		ret = (unsigned char *) cur + sizeof(struct memory_header_s);
-		memset(ret, 0, original_len);
+		(void)memset(ret, 0, original_len);
 
 		return ret;
 	}
@@ -245,7 +247,7 @@
 	}
 
 	ret = (unsigned char *) cur + sizeof(struct memory_header_s);
-	memset(ret, 0, original_len);
+	(void)memset(ret, 0, original_len);
 
 	return ret;
 }
@@ -265,11 +267,11 @@
 	struct memory_header_s *old = NULL;
 	unsigned char *p = (unsigned char *) ptr;
 
-	if (ptr == NULL || heap->buf == NULL || heap->first == NULL) {
+	if ((ptr == NULL) || (heap->buf == NULL) || (heap->first == NULL)) {
 		return;
 	}
 
-	if (p < heap->buf || p >= heap->buf + heap->len) {
+	if ((p < heap->buf) || (p >= (heap->buf + heap->len))) {
 		assert(0);
 	}
 
@@ -285,7 +287,7 @@
 	hdr->alloc = 0;
 
 	/* Regroup with block before */
-	if (hdr->prev != NULL && hdr->prev->alloc == 0UL) {
+	if ((hdr->prev != NULL) && (hdr->prev->alloc == 0UL)) {
 		hdr->prev->size += sizeof(struct memory_header_s) + hdr->size;
 		hdr->prev->next = hdr->next;
 		old = hdr;
@@ -295,16 +297,16 @@
 			hdr->next->prev = hdr;
 		}
 
-		memset(old, 0, sizeof(struct memory_header_s));
+		(void)memset(old, 0, sizeof(struct memory_header_s));
 	}
 
 	/* Regroup with block after */
-	if (hdr->next != NULL && hdr->next->alloc == 0UL) {
+	if ((hdr->next != NULL) && (hdr->next->alloc == 0UL)) {
 		hdr->size += sizeof(struct memory_header_s) + hdr->next->size;
 		old = hdr->next;
 		hdr->next = hdr->next->next;
 
-		if (hdr->prev_free != NULL || hdr->next_free != NULL) {
+		if ((hdr->prev_free != NULL) || (hdr->next_free != NULL)) {
 			if (hdr->prev_free != NULL) {
 				hdr->prev_free->next_free = hdr->next_free;
 			} else {
@@ -332,7 +334,7 @@
 			hdr->next->prev = hdr;
 		}
 
-		memset(old, 0, sizeof(struct memory_header_s));
+		(void)memset(old, 0, sizeof(struct memory_header_s));
 	}
 
 	/*
@@ -347,7 +349,7 @@
 		heap->first_free = hdr;
 	}
 
-	if (heap->verify & MBEDTLS_MEMORY_VERIFY_FREE) {
+	if ((heap->verify & MBEDTLS_MEMORY_VERIFY_FREE) != 0) {
 		assert(verify_chain(heap));
 	}
 }
@@ -419,12 +421,12 @@
 
 	assert(heap);
 
-	memset(heap, 0, sizeof(struct buffer_alloc_ctx));
+	(void)memset(heap, 0, sizeof(struct buffer_alloc_ctx));
 
 	if (len < sizeof(struct memory_header_s) +
 	    MBEDTLS_MEMORY_ALIGN_MULTIPLE) {
 		return;
-	} else if ((size_t)buf % MBEDTLS_MEMORY_ALIGN_MULTIPLE)	{
+	} else if (((size_t)buf % MBEDTLS_MEMORY_ALIGN_MULTIPLE) != 0U) {
 		/* Adjust len first since buf is used in the computation */
 		len -= MBEDTLS_MEMORY_ALIGN_MULTIPLE
 			- ((size_t)buf % MBEDTLS_MEMORY_ALIGN_MULTIPLE);
@@ -432,7 +434,7 @@
 			- ((size_t)buf % MBEDTLS_MEMORY_ALIGN_MULTIPLE);
 	}
 
-	memset(buf, 0, len);
+	(void)memset(buf, 0, len);
 
 	heap->buf = buf;
 	heap->len = len;
@@ -449,5 +451,5 @@
 	struct buffer_alloc_ctx *heap = get_heap_ctx();
 
 	assert(heap);
-	memset(heap, 0, sizeof(struct buffer_alloc_ctx));
+	(void)memset(heap, 0, sizeof(struct buffer_alloc_ctx));
 }