From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7CE2F82026 for ; Thu, 15 Dec 2016 19:38:43 -0800 (PST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP; 15 Dec 2016 19:38:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,355,1477983600"; d="scan'208";a="42940876" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.34]) by orsmga005.jf.intel.com with ESMTP; 15 Dec 2016 19:38:41 -0800 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Jiewen Yao , Liming Gao , Michael D Kinney Date: Fri, 16 Dec 2016 11:37:40 +0800 Message-Id: <1481859463-10536-4-git-send-email-hao.a.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1481859463-10536-1-git-send-email-hao.a.wu@intel.com> References: <1481859463-10536-1-git-send-email-hao.a.wu@intel.com> Subject: [PATCH v2 3/6] MdePkg/MemoryLib: Refine InternalMemSetMem16|32|64 functions logic X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Dec 2016 03:38:43 -0000 This commit refines the logic for InternalMemSetMem16|32|64 functions. It avoids using the decrement operator '--' for array index to prevent possible mis-reports by static code checkers. Please note that those modified functions are only consumed within MemoryLib by APIs SetMem16|32|64, and those APIs will handle the case when the input number of bytes to set is 0. Hence, the behavior of APIs SetMem16|32|64 is not changed. Cc: Jiewen Yao Cc: Liming Gao Cc: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu Reviewed-by: Michael Kinney --- MdePkg/Library/BaseMemoryLib/MemLibGeneric.c | 18 +++++++++--------- MdePkg/Library/PeiMemoryLib/MemLibGeneric.c | 18 +++++++++--------- MdePkg/Library/UefiMemoryLib/MemLibGeneric.c | 18 +++++++++--------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c b/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c index b058be8..cf40ace 100644 --- a/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c +++ b/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c @@ -37,9 +37,9 @@ InternalMemSetMem16 ( IN UINT16 Value ) { - do { - ((UINT16*)Buffer)[--Length] = Value; - } while (Length != 0); + for (; Length != 0; Length--) { + ((UINT16*)Buffer)[Length - 1] = Value; + } return Buffer; } @@ -61,9 +61,9 @@ InternalMemSetMem32 ( IN UINT32 Value ) { - do { - ((UINT32*)Buffer)[--Length] = Value; - } while (Length != 0); + for (; Length != 0; Length--) { + ((UINT32*)Buffer)[Length - 1] = Value; + } return Buffer; } @@ -85,9 +85,9 @@ InternalMemSetMem64 ( IN UINT64 Value ) { - do { - ((UINT64*)Buffer)[--Length] = Value; - } while (Length != 0); + for (; Length != 0; Length--) { + ((UINT64*)Buffer)[Length - 1] = Value; + } return Buffer; } diff --git a/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c b/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c index 490b244..ed18b57 100644 --- a/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c +++ b/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c @@ -37,9 +37,9 @@ InternalMemSetMem16 ( IN UINT16 Value ) { - do { - ((UINT16*)Buffer)[--Length] = Value; - } while (Length != 0); + for (; Length != 0; Length--) { + ((UINT16*)Buffer)[Length - 1] = Value; + } return Buffer; } @@ -61,9 +61,9 @@ InternalMemSetMem32 ( IN UINT32 Value ) { - do { - ((UINT32*)Buffer)[--Length] = Value; - } while (Length != 0); + for (; Length != 0; Length--) { + ((UINT32*)Buffer)[Length - 1] = Value; + } return Buffer; } @@ -85,9 +85,9 @@ InternalMemSetMem64 ( IN UINT64 Value ) { - do { - ((UINT64*)Buffer)[--Length] = Value; - } while (Length != 0); + for (; Length != 0; Length--) { + ((UINT64*)Buffer)[Length - 1] = Value; + } return Buffer; } diff --git a/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c b/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c index da02b6c..f1efdbb 100644 --- a/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c +++ b/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c @@ -37,9 +37,9 @@ InternalMemSetMem16 ( IN UINT16 Value ) { - do { - ((UINT16*)Buffer)[--Length] = Value; - } while (Length != 0); + for (; Length != 0; Length--) { + ((UINT16*)Buffer)[Length - 1] = Value; + } return Buffer; } @@ -61,9 +61,9 @@ InternalMemSetMem32 ( IN UINT32 Value ) { - do { - ((UINT32*)Buffer)[--Length] = Value; - } while (Length != 0); + for (; Length != 0; Length--) { + ((UINT32*)Buffer)[Length - 1] = Value; + } return Buffer; } @@ -85,9 +85,9 @@ InternalMemSetMem64 ( IN UINT64 Value ) { - do { - ((UINT64*)Buffer)[--Length] = Value; - } while (Length != 0); + for (; Length != 0; Length--) { + ((UINT64*)Buffer)[Length - 1] = Value; + } return Buffer; } -- 1.9.5.msysgit.0