From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 B2CD281FD5 for ; Thu, 15 Dec 2016 15:55:27 -0800 (PST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP; 15 Dec 2016 15:55:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,354,1477983600"; d="scan'208";a="912712279" Received: from orsmsx107.amr.corp.intel.com ([10.22.240.5]) by orsmga003.jf.intel.com with ESMTP; 15 Dec 2016 15:55:27 -0800 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.227]) by ORSMSX107.amr.corp.intel.com ([169.254.1.181]) with mapi id 14.03.0248.002; Thu, 15 Dec 2016 15:55:26 -0800 From: "Kinney, Michael D" To: "Wu, Hao A" , "edk2-devel@lists.01.org" , "Kinney, Michael D" CC: "Yao, Jiewen" , "Gao, Liming" Thread-Topic: [PATCH 3/6] MdePkg/MemoryLib: Refine InternalMemSetMem16|32|64 functions logic Thread-Index: AQHSVf0DYUYm8rkHx023a5LTxGHIjqEJsWSA Date: Thu, 15 Dec 2016 23:55:26 +0000 Message-ID: References: <1481714811-12568-1-git-send-email-hao.a.wu@intel.com> <1481714811-12568-4-git-send-email-hao.a.wu@intel.com> In-Reply-To: <1481714811-12568-4-git-send-email-hao.a.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_IC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZDcxNDA1MjMtODk4MC00MGVhLTgwNmYtNDQyMDk1MWYzNGIxIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6InV3VGpKaCtHQmZwUUwwS1ZWYUd5SDFDY0h6SXp5Q1wvUlwvN2lxVDJsVng4TT0ifQ== x-originating-ip: [10.22.254.138] MIME-Version: 1.0 Subject: Re: [PATCH 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: Thu, 15 Dec 2016 23:55:27 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Michael Kinney > -----Original Message----- > From: Wu, Hao A > Sent: Wednesday, December 14, 2016 3:27 AM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A ; Yao, Jiewen ; G= ao, Liming > ; Kinney, Michael D > Subject: [PATCH 3/6] MdePkg/MemoryLib: Refine InternalMemSetMem16|32|64 f= unctions > logic >=20 > 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. >=20 > Please note that those modified functions are only consumed within > MemoryLib by APIs SetMem16|32|64, and those APIs will handle the case whe= n > the input number of bytes to set is 0. Hence, the behavior of APIs > SetMem16|32|64 is not changed. >=20 > Cc: Jiewen Yao > Cc: Liming Gao > Cc: Michael D Kinney > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Hao Wu > --- > 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(-) >=20 > 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] =3D Value; > - } while (Length !=3D 0); > + for (; Length !=3D 0; Length--) { > + ((UINT16*)Buffer)[Length - 1] =3D Value; > + } > return Buffer; > } >=20 > @@ -61,9 +61,9 @@ InternalMemSetMem32 ( > IN UINT32 Value > ) > { > - do { > - ((UINT32*)Buffer)[--Length] =3D Value; > - } while (Length !=3D 0); > + for (; Length !=3D 0; Length--) { > + ((UINT32*)Buffer)[Length - 1] =3D Value; > + } > return Buffer; > } >=20 > @@ -85,9 +85,9 @@ InternalMemSetMem64 ( > IN UINT64 Value > ) > { > - do { > - ((UINT64*)Buffer)[--Length] =3D Value; > - } while (Length !=3D 0); > + for (; Length !=3D 0; Length--) { > + ((UINT64*)Buffer)[Length - 1] =3D Value; > + } > return Buffer; > } >=20 > 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] =3D Value; > - } while (Length !=3D 0); > + for (; Length !=3D 0; Length--) { > + ((UINT16*)Buffer)[Length - 1] =3D Value; > + } > return Buffer; > } >=20 > @@ -61,9 +61,9 @@ InternalMemSetMem32 ( > IN UINT32 Value > ) > { > - do { > - ((UINT32*)Buffer)[--Length] =3D Value; > - } while (Length !=3D 0); > + for (; Length !=3D 0; Length--) { > + ((UINT32*)Buffer)[Length - 1] =3D Value; > + } > return Buffer; > } >=20 > @@ -85,9 +85,9 @@ InternalMemSetMem64 ( > IN UINT64 Value > ) > { > - do { > - ((UINT64*)Buffer)[--Length] =3D Value; > - } while (Length !=3D 0); > + for (; Length !=3D 0; Length--) { > + ((UINT64*)Buffer)[Length - 1] =3D Value; > + } > return Buffer; > } >=20 > 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] =3D Value; > - } while (Length !=3D 0); > + for (; Length !=3D 0; Length--) { > + ((UINT16*)Buffer)[Length - 1] =3D Value; > + } > return Buffer; > } >=20 > @@ -61,9 +61,9 @@ InternalMemSetMem32 ( > IN UINT32 Value > ) > { > - do { > - ((UINT32*)Buffer)[--Length] =3D Value; > - } while (Length !=3D 0); > + for (; Length !=3D 0; Length--) { > + ((UINT32*)Buffer)[Length - 1] =3D Value; > + } > return Buffer; > } >=20 > @@ -85,9 +85,9 @@ InternalMemSetMem64 ( > IN UINT64 Value > ) > { > - do { > - ((UINT64*)Buffer)[--Length] =3D Value; > - } while (Length !=3D 0); > + for (; Length !=3D 0; Length--) { > + ((UINT64*)Buffer)[Length - 1] =3D Value; > + } > return Buffer; > } >=20 > -- > 1.9.5.msysgit.0