From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.53.1608139344043945646 for ; Wed, 16 Dec 2020 09:22:24 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: pierre.gondois@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AC5D01FB; Wed, 16 Dec 2020 09:22:23 -0800 (PST) Received: from e120189.arm.com (unknown [10.57.25.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8A05C3F66E; Wed, 16 Dec 2020 09:22:22 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io, ard.biesheuvel@arm.com, leif@nuviainc.com Cc: sami.mujawar@arm.com Subject: [PATCH v1 02/25] ArmPkg: Fix Ecc error 3002 in CompilerIntrinsicsLib Date: Wed, 16 Dec 2020 17:21:37 +0000 Message-Id: <20201216172200.25846-3-Pierre.Gondois@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216172200.25846-1-Pierre.Gondois@arm.com> References: <20201216172200.25846-1-Pierre.Gondois@arm.com> From: Pierre Gondois This patch fixes the following Ecc reported error: Non-Boolean comparisons should use a compare operator (==, !=, >, < >=, <=) Brackets are also added to comply to with the coding standard. Signed-off-by: Pierre Gondois --- The changes can be seen at: https://github.com/PierreARM/edk2/commits/1552_Ecc_ArmPkg_v1 ArmPkg/Library/CompilerIntrinsicsLib/memcmp_ms.c | 3 ++- ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c | 4 +++- ArmPkg/Library/CompilerIntrinsicsLib/memcpy_ms.c | 4 +++- ArmPkg/Library/CompilerIntrinsicsLib/memmove_ms.c | 7 +++++-- ArmPkg/Library/CompilerIntrinsicsLib/memset.c | 4 +++- ArmPkg/Library/CompilerIntrinsicsLib/memset_ms.c | 4 +++- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/memcmp_ms.c b/ArmPkg/Library/CompilerIntrinsicsLib/memcmp_ms.c index 551f8e77c12f..8491e2401f1e 100644 --- a/ArmPkg/Library/CompilerIntrinsicsLib/memcmp_ms.c +++ b/ArmPkg/Library/CompilerIntrinsicsLib/memcmp_ms.c @@ -1,6 +1,7 @@ //------------------------------------------------------------------------------ // // Copyright (c) 2019, Pete Batard. All rights reserved. +// Copyright (c) 2020, Arm Limited. All rights reserved.
// // SPDX-License-Identifier: BSD-2-Clause-Patent // @@ -20,7 +21,7 @@ int memcmp(const void *s1, const void *s2, size_t n) unsigned char const *t1 = s1; unsigned char const *t2 = s2; - while (n--) { + while (n-- != 0) { if (*t1 != *t2) return (int)*t1 - (int)*t2; t1++; diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c b/ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c index 6e9c85f4bafd..d4827531dd04 100644 --- a/ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c +++ b/ArmPkg/Library/CompilerIntrinsicsLib/memcpy.c @@ -1,6 +1,7 @@ //------------------------------------------------------------------------------ // // Copyright (c) 2016, Linaro Ltd. All rights reserved.
+// Copyright (c) 2020, Arm Limited. All rights reserved.
// // SPDX-License-Identifier: BSD-2-Clause-Patent // @@ -13,8 +14,9 @@ static void __memcpy(void *dest, const void *src, size_t n) unsigned char *d = dest; unsigned char const *s = src; - while (n--) + while (n-- != 0) { *d++ = *s++; + } } void *memcpy(void *dest, const void *src, size_t n) diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/memcpy_ms.c b/ArmPkg/Library/CompilerIntrinsicsLib/memcpy_ms.c index 34feef5a4bb9..a9590df68054 100644 --- a/ArmPkg/Library/CompilerIntrinsicsLib/memcpy_ms.c +++ b/ArmPkg/Library/CompilerIntrinsicsLib/memcpy_ms.c @@ -1,6 +1,7 @@ //------------------------------------------------------------------------------ // // Copyright (c) 2017, Pete Batard. All rights reserved.
+// Copyright (c) 2020, Arm Limited. All rights reserved.
// // SPDX-License-Identifier: BSD-2-Clause-Patent // @@ -20,8 +21,9 @@ void* memcpy(void *dest, const void *src, size_t n) unsigned char *d = dest; unsigned char const *s = src; - while (n--) + while (n-- != 0) { *d++ = *s++; + } return dest; } diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/memmove_ms.c b/ArmPkg/Library/CompilerIntrinsicsLib/memmove_ms.c index 5b261ef8b948..a2e1ef9c8883 100644 --- a/ArmPkg/Library/CompilerIntrinsicsLib/memmove_ms.c +++ b/ArmPkg/Library/CompilerIntrinsicsLib/memmove_ms.c @@ -1,6 +1,7 @@ //------------------------------------------------------------------------------ // // Copyright (c) 2019, Pete Batard. All rights reserved. +// Copyright (c) 2020, Arm Limited. All rights reserved.
// // SPDX-License-Identifier: BSD-2-Clause-Patent // @@ -21,13 +22,15 @@ void* memmove(void *dest, const void *src, size_t n) unsigned char const *s = src; if (d < s) { - while (n--) + while (n-- != 0) { *d++ = *s++; + } } else { d += n; s += n; - while (n--) + while (n-- != 0) { *--d = *--s; + } } return dest; diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/memset.c b/ArmPkg/Library/CompilerIntrinsicsLib/memset.c index 24398d591f79..57fc776333b0 100644 --- a/ArmPkg/Library/CompilerIntrinsicsLib/memset.c +++ b/ArmPkg/Library/CompilerIntrinsicsLib/memset.c @@ -1,6 +1,7 @@ //------------------------------------------------------------------------------ // // Copyright (c) 2016, Linaro Ltd. All rights reserved.
+// Copyright (c) 2020, Arm Limited. All rights reserved.
// // SPDX-License-Identifier: BSD-2-Clause-Patent // @@ -13,8 +14,9 @@ void *__memset(void *s, int c, size_t n) { unsigned char *d = s; - while (n--) + while (n-- != 0) { *d++ = c; + } return s; } diff --git a/ArmPkg/Library/CompilerIntrinsicsLib/memset_ms.c b/ArmPkg/Library/CompilerIntrinsicsLib/memset_ms.c index 4de55d845718..463fc21d3184 100644 --- a/ArmPkg/Library/CompilerIntrinsicsLib/memset_ms.c +++ b/ArmPkg/Library/CompilerIntrinsicsLib/memset_ms.c @@ -1,6 +1,7 @@ //------------------------------------------------------------------------------ // // Copyright (c) 2017, Pete Batard. All rights reserved.
+// Copyright (c) 2020, Arm Limited. All rights reserved.
// // SPDX-License-Identifier: BSD-2-Clause-Patent // @@ -19,8 +20,9 @@ void *memset(void *s, int c, size_t n) { unsigned char *d = s; - while (n--) + while (n-- != 0) { *d++ = (unsigned char)c; + } return s; } -- 2.17.1