From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,252,1484035200"; d="scan'208";a="72015630" 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 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Hao A Wu 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: [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: , X-List-Received-Date: Mon, 06 Mar 2017 07:24:30 -0000 The change doesn't impact the functionality. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Hao A 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/SafeString.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 characters is no more than 4. // + ASSERT (AddressIndex + 1 < ARRAY_SIZE (Address->Addr)); LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uintn >> 8); LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uintn; AddressIndex += 2; @@ -1286,11 +1287,13 @@ StrToIpv6Address ( } CopyMem (&Address->Addr[0], &LocalAddress.Addr[0], CompressStart); ZeroMem (&Address->Addr[CompressStart], ARRAY_SIZE (Address->Addr) - AddressIndex); - CopyMem ( - &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressIndex], - &LocalAddress.Addr[CompressStart], - AddressIndex - CompressStart - ); + if (AddressIndex > CompressStart) { + CopyMem ( + &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressIndex], + &LocalAddress.Addr[CompressStart], + AddressIndex - CompressStart + ); + } if (PrefixLength != NULL) { *PrefixLength = LocalPrefixLength; @@ -3204,6 +3207,7 @@ AsciiStrToIpv6Address ( // // Uintn won't exceed MAX_UINT16 if number of hexadecimal digit characters is no more than 4. // + ASSERT (AddressIndex + 1 < ARRAY_SIZE (Address->Addr)); LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uintn >> 8); LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uintn; AddressIndex += 2; @@ -3256,11 +3260,13 @@ AsciiStrToIpv6Address ( } CopyMem (&Address->Addr[0], &LocalAddress.Addr[0], CompressStart); ZeroMem (&Address->Addr[CompressStart], ARRAY_SIZE (Address->Addr) - AddressIndex); - CopyMem ( - &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressIndex], - &LocalAddress.Addr[CompressStart], - AddressIndex - CompressStart - ); + if (AddressIndex > CompressStart) { + CopyMem ( + &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressIndex], + &LocalAddress.Addr[CompressStart], + AddressIndex - CompressStart + ); + } if (PrefixLength != NULL) { *PrefixLength = LocalPrefixLength; -- 2.9.0.windows.1