From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 D201382319 for ; Wed, 21 Dec 2016 19:28:03 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP; 21 Dec 2016 19:28:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,386,1477983600"; d="scan'208";a="1102777451" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga002.fm.intel.com with ESMTP; 21 Dec 2016 19:28:03 -0800 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 21 Dec 2016 19:28:03 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX157.amr.corp.intel.com (10.18.116.73) with Microsoft SMTP Server (TLS) id 14.3.248.2; Wed, 21 Dec 2016 19:28:02 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.88]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.204]) with mapi id 14.03.0248.002; Thu, 22 Dec 2016 11:28:00 +0800 From: "Gao, Liming" To: "Wu, Hao A" , "edk2-devel@lists.01.org" CC: "Yao, Jiewen" , "Kinney, Michael D" Thread-Topic: [PATCH v2 1/6] MdePkg/BaseLib: Refine (Ascii)StrnLenS functions logic Thread-Index: AQHSV03mylTwfB4Szk2oukO4b6FUfaETTpMw Date: Thu, 22 Dec 2016 03:28:00 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14D6C3235@shsmsx102.ccr.corp.intel.com> References: <1481859463-10536-1-git-send-email-hao.a.wu@intel.com> <1481859463-10536-2-git-send-email-hao.a.wu@intel.com> In-Reply-To: <1481859463-10536-2-git-send-email-hao.a.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2 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, 22 Dec 2016 03:28:03 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao > -----Original Message----- > From: Wu, Hao A > Sent: Friday, December 16, 2016 11:38 AM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A ; Yao, Jiewen ; > Gao, Liming ; Kinney, Michael D > > Subject: [PATCH v2 1/6] MdePkg/BaseLib: Refine (Ascii)StrnLenS functions > 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..e4c0759 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 > characters 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 - 1) { > + return MaxSize; > + } > + 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 - 1) { > + return MaxSize; > + } > + Length++; > } > return Length; > } > -- > 1.9.5.msysgit.0