summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2017-03-06 14:34:29 +0800
committerRuiyu Ni <ruiyu.ni@intel.com>2017-03-07 13:14:17 +0800
commit5b0ce08a3ee87a9d3fd3ecabfb1a94b5a209fb6c (patch)
tree4aa99c433731bd61fc8483a3a978ec7bcf9b9472 /MdePkg/Library
parent8994d2f95cc77a09a37e87ad6e4e4858615c3b9e (diff)
downloadedk2-5b0ce08a3ee87a9d3fd3ecabfb1a94b5a209fb6c.tar.gz
edk2-5b0ce08a3ee87a9d3fd3ecabfb1a94b5a209fb6c.tar.bz2
edk2-5b0ce08a3ee87a9d3fd3ecabfb1a94b5a209fb6c.zip
MdePkg/SafeString.c: Fix code to be more readable
The change doesn't impact the functionality. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Diffstat (limited to 'MdePkg/Library')
-rw-r--r--MdePkg/Library/BaseLib/SafeString.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/MdePkg/Library/BaseLib/SafeString.c b/MdePkg/Library/BaseLib/SafeString.c
index b7895adfc0..249fe477b4 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;