From nobody Sat Nov 2 12:19:09 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 14887850737111016.8309827599296; Sun, 5 Mar 2017 23:24:33 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 443C38030A; Sun, 5 Mar 2017 23:24:32 -0800 (PST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 976BB802F8 for ; Sun, 5 Mar 2017 23:24:30 -0800 (PST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2017 23:24:30 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga005.jf.intel.com with ESMTP; 05 Mar 2017 23:24:29 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,252,1484035200"; d="scan'208";a="72015630" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Mon, 6 Mar 2017 15:24:27 +0800 Message-Id: <20170306072427.601984-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 Subject: [edk2] [PATCH] MdePkg/SafeString.c: Fix code to be more readable 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: , Cc: Hao A Wu MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The change doesn't impact the functionality. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Hao A Wu Reviewed-by: Hao Wu --- MdePkg/Library/BaseLib/SafeString.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/MdePkg/Library/BaseLib/SafeString.c b/MdePkg/Library/BaseLib/S= afeString.c index b7895ad..249fe47 100644 --- a/MdePkg/Library/BaseLib/SafeString.c +++ b/MdePkg/Library/BaseLib/SafeString.c @@ -1234,6 +1234,7 @@ StrToIpv6Address ( // // Uintn won't exceed MAX_UINT16 if number of hexadecimal digit ch= aracters is no more than 4. // + ASSERT (AddressIndex + 1 < ARRAY_SIZE (Address->Addr)); LocalAddress.Addr[AddressIndex] =3D (UINT8) ((UINT16) Uintn >> 8); LocalAddress.Addr[AddressIndex + 1] =3D (UINT8) Uintn; AddressIndex +=3D 2; @@ -1286,11 +1287,13 @@ StrToIpv6Address ( } CopyMem (&Address->Addr[0], &LocalAddress.Addr[0], CompressStart); ZeroMem (&Address->Addr[CompressStart], ARRAY_SIZE (Address->Addr) - Add= ressIndex); - CopyMem ( - &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressInd= ex], - &LocalAddress.Addr[CompressStart], - AddressIndex - CompressStart - ); + if (AddressIndex > CompressStart) { + CopyMem ( + &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressI= ndex], + &LocalAddress.Addr[CompressStart], + AddressIndex - CompressStart + ); + } =20 if (PrefixLength !=3D NULL) { *PrefixLength =3D LocalPrefixLength; @@ -3204,6 +3207,7 @@ AsciiStrToIpv6Address ( // // Uintn won't exceed MAX_UINT16 if number of hexadecimal digit ch= aracters is no more than 4. // + ASSERT (AddressIndex + 1 < ARRAY_SIZE (Address->Addr)); LocalAddress.Addr[AddressIndex] =3D (UINT8) ((UINT16) Uintn >> 8); LocalAddress.Addr[AddressIndex + 1] =3D (UINT8) Uintn; AddressIndex +=3D 2; @@ -3256,11 +3260,13 @@ AsciiStrToIpv6Address ( } CopyMem (&Address->Addr[0], &LocalAddress.Addr[0], CompressStart); ZeroMem (&Address->Addr[CompressStart], ARRAY_SIZE (Address->Addr) - Add= ressIndex); - CopyMem ( - &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressInd= ex], - &LocalAddress.Addr[CompressStart], - AddressIndex - CompressStart - ); + if (AddressIndex > CompressStart) { + CopyMem ( + &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressI= ndex], + &LocalAddress.Addr[CompressStart], + AddressIndex - CompressStart + ); + } =20 if (PrefixLength !=3D NULL) { *PrefixLength =3D LocalPrefixLength; --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel