Fix check_[uptr/u32]_overflow() macros MISRA defects

Add missing parentheses to fix MISRA C-2012 Rule 12.1.

Also, the result of a comparison is an essentially boolean value, it
isn't needed to return 1 or 0 depending on it.

Also, fix header guards (MISRA C-2012 Rule 21.1).

Change-Id: I90c0bcdeb2787c1ca659fc9a981808ece7958de3
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
This commit is contained in:
Antonio Nino Diaz 2018-07-18 13:23:07 +01:00
parent 029f5a28a8
commit f00119de57
1 changed files with 7 additions and 7 deletions

View File

@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __UTILS_DEF_H__
#define __UTILS_DEF_H__
#ifndef UTILS_DEF_H
#define UTILS_DEF_H
/* Compute the number of elements in the given array */
#define ARRAY_SIZE(a) \
@ -88,15 +88,15 @@
* Evaluates to 1 if (ptr + inc) overflows, 0 otherwise.
* Both arguments must be unsigned pointer values (i.e. uintptr_t).
*/
#define check_uptr_overflow(ptr, inc) \
(((ptr) > UINTPTR_MAX - (inc)) ? 1 : 0)
#define check_uptr_overflow(_ptr, _inc) \
((_ptr) > (UINTPTR_MAX - (_inc)))
/*
* Evaluates to 1 if (u32 + inc) overflows, 0 otherwise.
* Both arguments must be 32-bit unsigned integers (i.e. effectively uint32_t).
*/
#define check_u32_overflow(u32, inc) \
((u32) > (UINT32_MAX - (inc)) ? 1 : 0)
#define check_u32_overflow(_u32, _inc) \
((_u32) > (UINT32_MAX - (_inc)))
/*
* For those constants to be shared between C and other sources, apply a 'U',
@ -153,4 +153,4 @@
#define ASSERT_SYM_PTR_ALIGN(sym) assert(((size_t)(sym) % __alignof__(*(sym))) == 0)
#endif /* __UTILS_DEF_H__ */
#endif /* UTILS_DEF_H */