* [PATCH] MdePkg/SafeString.c: Fix code to be more readable
@ 2017-03-06 7:24 Ruiyu Ni
2017-03-06 7:27 ` Wu, Hao A
0 siblings, 1 reply; 2+ messages in thread
From: Ruiyu Ni @ 2017-03-06 7:24 UTC (permalink / raw)
To: edk2-devel; +Cc: Hao A Wu
The change doesn't impact the functionality.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] MdePkg/SafeString.c: Fix code to be more readable
2017-03-06 7:24 [PATCH] MdePkg/SafeString.c: Fix code to be more readable Ruiyu Ni
@ 2017-03-06 7:27 ` Wu, Hao A
0 siblings, 0 replies; 2+ messages in thread
From: Wu, Hao A @ 2017-03-06 7:27 UTC (permalink / raw)
To: Ni, Ruiyu, edk2-devel@lists.01.org
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
Best Regards,
Hao Wu
> -----Original Message-----
> From: Ni, Ruiyu
> Sent: Monday, March 06, 2017 3:24 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A
> Subject: [PATCH] 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>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> ---
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-03-06 7:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-06 7:24 [PATCH] MdePkg/SafeString.c: Fix code to be more readable Ruiyu Ni
2017-03-06 7:27 ` Wu, Hao A
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox