From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 972EB81FD5 for ; Thu, 15 Dec 2016 15:54:45 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 15 Dec 2016 15:54:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,354,1477983600"; d="scan'208";a="798501928" Received: from orsmsx104.amr.corp.intel.com ([10.22.225.131]) by FMSMGA003.fm.intel.com with ESMTP; 15 Dec 2016 15:54:43 -0800 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.227]) by ORSMSX104.amr.corp.intel.com ([169.254.4.180]) with mapi id 14.03.0248.002; Thu, 15 Dec 2016 15:54:41 -0800 From: "Kinney, Michael D" To: "Wu, Hao A" , "edk2-devel@lists.01.org" , "Kinney, Michael D" CC: "Wu, Hao A" , "Yao, Jiewen" , "Gao, Liming" Thread-Topic: [edk2] [PATCH 1/6] MdePkg/BaseLib: Refine (Ascii)StrnLenS functions logic Thread-Index: AQHSVfz+QSJ3bznfSUGrZY2ji8tU9aEJsRcQ Date: Thu, 15 Dec 2016 23:54:40 +0000 Message-ID: References: <1481714811-12568-1-git-send-email-hao.a.wu@intel.com> <1481714811-12568-2-git-send-email-hao.a.wu@intel.com> In-Reply-To: <1481714811-12568-2-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: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNjY5NjVkYmYtZDFjMy00MGU2LTlkYjgtODc5YjJmODM0NTcwIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6Ims0UUlhblk1cXdaZGFhdFdQQlVqUmo4a01LZlZHK1lxUjJtbjZNbDBLdTQ9In0= x-originating-ip: [10.22.254.138] MIME-Version: 1.0 Subject: Re: [PATCH 1/6] MdePkg/BaseLib: Refine (Ascii)StrnLenS 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:54:45 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Michael Kinney > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ha= o Wu > Sent: Wednesday, December 14, 2016 3:27 AM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A ; Kinney, Michael D ; > Yao, Jiewen ; Gao, Liming > Subject: [edk2] [PATCH 1/6] MdePkg/BaseLib: Refine (Ascii)StrnLenS functi= ons logic >=20 > This commit refines the logic for AsciiStrnLenS and StrnLenS. It makes th= e > logic more straightforward to prevent possible mis-reports by static code > checkers. >=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/BaseLib/SafeString.c | 16 ++++++++++++---- > 1 file changed, 12 insertions(+), 4 deletions(-) >=20 > diff --git a/MdePkg/Library/BaseLib/SafeString.c > b/MdePkg/Library/BaseLib/SafeString.c > index ede2f4c..3247d28 100644 > --- a/MdePkg/Library/BaseLib/SafeString.c > +++ b/MdePkg/Library/BaseLib/SafeString.c > @@ -143,8 +143,12 @@ StrnLenS ( > // String then StrnLenS returns MaxSize. At most the first MaxSize cha= racters of > String shall > // be accessed by StrnLenS. > // > - for (Length =3D 0; (Length < MaxSize) && (*String !=3D 0); String++, L= ength++) { > - ; > + Length =3D 0; > + while (String[Length] !=3D 0) { > + if (Length >=3D MaxSize) { > + break; > + } > + Length++; > } > return Length; > } > @@ -571,8 +575,12 @@ AsciiStrnLenS ( > // String then AsciiStrnLenS returns MaxSize. At most the first MaxSiz= e characters > of String shall > // be accessed by AsciiStrnLenS. > // > - for (Length =3D 0; (Length < MaxSize) && (*String !=3D 0); String++, L= ength++) { > - ; > + Length =3D 0; > + while (String[Length] !=3D 0) { > + if (Length >=3D MaxSize) { > + break; > + } > + Length++; > } > return Length; > } > -- > 1.9.5.msysgit.0 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel