]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/SafeString.c
MdePkg/BaseIoLibIntrinsicArmVirt ARM: avoid double word loads and stores
[mirror_edk2.git] / MdePkg / Library / BaseLib / SafeString.c
index 249fe477b444d71a3edde09c05071f7f3fc82f32..417497cbc96a47aae6f54998df8407c742a78e00 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Safe String functions.\r
 \r
-  Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -217,7 +217,7 @@ StrnSizeS (
   @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
                                    If Source is NULL.\r
                                    If PcdMaximumUnicodeStringLength is not zero,\r
-                                    and DestMax is greater than \r
+                                    and DestMax is greater than\r
                                     PcdMaximumUnicodeStringLength.\r
                                    If DestMax is 0.\r
   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
@@ -231,7 +231,7 @@ StrCpyS (
   )\r
 {\r
   UINTN            SourceLen;\r
-  \r
+\r
   ASSERT (((UINTN) Destination & BIT0) == 0);\r
   ASSERT (((UINTN) Source & BIT0) == 0);\r
 \r
@@ -296,12 +296,12 @@ StrCpyS (
   @param  Length                   The maximum number of Unicode characters to copy.\r
 \r
   @retval RETURN_SUCCESS           String is copied.\r
-  @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than \r
+  @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than\r
                                    MIN(StrLen(Source), Length).\r
   @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
                                    If Source is NULL.\r
                                    If PcdMaximumUnicodeStringLength is not zero,\r
-                                    and DestMax is greater than \r
+                                    and DestMax is greater than\r
                                     PcdMaximumUnicodeStringLength.\r
                                    If DestMax is 0.\r
   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
@@ -342,7 +342,7 @@ StrnCpyS (
   //\r
   // 4. If Length is not less than DestMax, then DestMax shall be greater than StrnLenS(Source, DestMax).\r
   //\r
-  SourceLen = StrnLenS (Source, DestMax);\r
+  SourceLen = StrnLenS (Source, MIN (DestMax, Length));\r
   if (Length >= DestMax) {\r
     SAFE_STRING_CONSTRAINT_CHECK ((DestMax > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
   }\r
@@ -361,7 +361,7 @@ StrnCpyS (
   // pointed to by Destination. If no null character was copied from Source, then Destination[Length] is set to a null\r
   // character.\r
   //\r
-  while ((*Source != 0) && (SourceLen > 0)) {\r
+  while ((SourceLen > 0) && (*Source != 0)) {\r
     *(Destination++) = *(Source++);\r
     SourceLen--;\r
   }\r
@@ -388,14 +388,14 @@ StrnCpyS (
   @param  Source                   A pointer to a Null-terminated Unicode string.\r
 \r
   @retval RETURN_SUCCESS           String is appended.\r
-  @retval RETURN_BAD_BUFFER_SIZE   If DestMax is NOT greater than \r
+  @retval RETURN_BAD_BUFFER_SIZE   If DestMax is NOT greater than\r
                                    StrLen(Destination).\r
   @retval RETURN_BUFFER_TOO_SMALL  If (DestMax - StrLen(Destination)) is NOT\r
                                    greater than StrLen(Source).\r
   @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
                                    If Source is NULL.\r
                                    If PcdMaximumUnicodeStringLength is not zero,\r
-                                    and DestMax is greater than \r
+                                    and DestMax is greater than\r
                                     PcdMaximumUnicodeStringLength.\r
                                    If DestMax is 0.\r
   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
@@ -411,7 +411,7 @@ StrCatS (
   UINTN               DestLen;\r
   UINTN               CopyLen;\r
   UINTN               SourceLen;\r
-  \r
+\r
   ASSERT (((UINTN) Destination & BIT0) == 0);\r
   ASSERT (((UINTN) Source & BIT0) == 0);\r
 \r
@@ -497,7 +497,7 @@ StrCatS (
   @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
                                    If Source is NULL.\r
                                    If PcdMaximumUnicodeStringLength is not zero,\r
-                                    and DestMax is greater than \r
+                                    and DestMax is greater than\r
                                     PcdMaximumUnicodeStringLength.\r
                                    If DestMax is 0.\r
   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
@@ -514,7 +514,7 @@ StrnCatS (
   UINTN               DestLen;\r
   UINTN               CopyLen;\r
   UINTN               SourceLen;\r
-  \r
+\r
   ASSERT (((UINTN) Destination & BIT0) == 0);\r
   ASSERT (((UINTN) Source & BIT0) == 0);\r
 \r
@@ -551,7 +551,7 @@ StrnCatS (
   //\r
   // 5. If Length is not less than CopyLen, then CopyLen shall be greater than StrnLenS(Source, CopyLen).\r
   //\r
-  SourceLen = StrnLenS (Source, CopyLen);\r
+  SourceLen = StrnLenS (Source, MIN (CopyLen, Length));\r
   if (Length >= CopyLen) {\r
     SAFE_STRING_CONSTRAINT_CHECK ((CopyLen > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
   }\r
@@ -572,7 +572,7 @@ StrnCatS (
   // a null character.\r
   //\r
   Destination = Destination + DestLen;\r
-  while ((*Source != 0) && (SourceLen > 0)) {\r
+  while ((SourceLen > 0) && (*Source != 0)) {\r
     *(Destination++) = *(Source++);\r
     SourceLen--;\r
   }\r
@@ -1799,7 +1799,7 @@ AsciiStrnSizeS (
   @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
                                    If Source is NULL.\r
                                    If PcdMaximumAsciiStringLength is not zero,\r
-                                    and DestMax is greater than \r
+                                    and DestMax is greater than\r
                                     PcdMaximumAsciiStringLength.\r
                                    If DestMax is 0.\r
   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
@@ -1813,7 +1813,7 @@ AsciiStrCpyS (
   )\r
 {\r
   UINTN            SourceLen;\r
-  \r
+\r
   //\r
   // 1. Neither Destination nor Source shall be a null pointer.\r
   //\r
@@ -1873,12 +1873,12 @@ AsciiStrCpyS (
   @param  Length                   The maximum number of Ascii characters to copy.\r
 \r
   @retval RETURN_SUCCESS           String is copied.\r
-  @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than \r
+  @retval RETURN_BUFFER_TOO_SMALL  If DestMax is NOT greater than\r
                                    MIN(StrLen(Source), Length).\r
   @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
                                    If Source is NULL.\r
                                    If PcdMaximumAsciiStringLength is not zero,\r
-                                    and DestMax is greater than \r
+                                    and DestMax is greater than\r
                                     PcdMaximumAsciiStringLength.\r
                                    If DestMax is 0.\r
   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
@@ -1916,7 +1916,7 @@ AsciiStrnCpyS (
   //\r
   // 4. If Length is not less than DestMax, then DestMax shall be greater than AsciiStrnLenS(Source, DestMax).\r
   //\r
-  SourceLen = AsciiStrnLenS (Source, DestMax);\r
+  SourceLen = AsciiStrnLenS (Source, MIN (DestMax, Length));\r
   if (Length >= DestMax) {\r
     SAFE_STRING_CONSTRAINT_CHECK ((DestMax > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
   }\r
@@ -1935,7 +1935,7 @@ AsciiStrnCpyS (
   // pointed to by Destination. If no null character was copied from Source, then Destination[Length] is set to a null\r
   // character.\r
   //\r
-  while ((*Source != 0) && (SourceLen > 0)) {\r
+  while ((SourceLen > 0) && (*Source != 0)) {\r
     *(Destination++) = *(Source++);\r
     SourceLen--;\r
   }\r
@@ -1960,14 +1960,14 @@ AsciiStrnCpyS (
   @param  Source                   A pointer to a Null-terminated Ascii string.\r
 \r
   @retval RETURN_SUCCESS           String is appended.\r
-  @retval RETURN_BAD_BUFFER_SIZE   If DestMax is NOT greater than \r
+  @retval RETURN_BAD_BUFFER_SIZE   If DestMax is NOT greater than\r
                                    StrLen(Destination).\r
   @retval RETURN_BUFFER_TOO_SMALL  If (DestMax - StrLen(Destination)) is NOT\r
                                    greater than StrLen(Source).\r
   @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
                                    If Source is NULL.\r
                                    If PcdMaximumAsciiStringLength is not zero,\r
-                                    and DestMax is greater than \r
+                                    and DestMax is greater than\r
                                     PcdMaximumAsciiStringLength.\r
                                    If DestMax is 0.\r
   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
@@ -1983,7 +1983,7 @@ AsciiStrCatS (
   UINTN               DestLen;\r
   UINTN               CopyLen;\r
   UINTN               SourceLen;\r
-  \r
+\r
   //\r
   // Let CopyLen denote the value DestMax - AsciiStrnLenS(Destination, DestMax) upon entry to AsciiStrCatS.\r
   //\r
@@ -2064,7 +2064,7 @@ AsciiStrCatS (
   @retval RETURN_INVALID_PARAMETER If Destination is NULL.\r
                                    If Source is NULL.\r
                                    If PcdMaximumAsciiStringLength is not zero,\r
-                                    and DestMax is greater than \r
+                                    and DestMax is greater than\r
                                     PcdMaximumAsciiStringLength.\r
                                    If DestMax is 0.\r
   @retval RETURN_ACCESS_DENIED     If Source and Destination overlap.\r
@@ -2081,7 +2081,7 @@ AsciiStrnCatS (
   UINTN               DestLen;\r
   UINTN               CopyLen;\r
   UINTN               SourceLen;\r
-  \r
+\r
   //\r
   // Let CopyLen denote the value DestMax - AsciiStrnLenS(Destination, DestMax) upon entry to AsciiStrnCatS.\r
   //\r
@@ -2115,7 +2115,7 @@ AsciiStrnCatS (
   //\r
   // 5. If Length is not less than CopyLen, then CopyLen shall be greater than AsciiStrnLenS(Source, CopyLen).\r
   //\r
-  SourceLen = AsciiStrnLenS (Source, CopyLen);\r
+  SourceLen = AsciiStrnLenS (Source, MIN (CopyLen, Length));\r
   if (Length >= CopyLen) {\r
     SAFE_STRING_CONSTRAINT_CHECK ((CopyLen > SourceLen), RETURN_BUFFER_TOO_SMALL);\r
   }\r
@@ -2136,7 +2136,7 @@ AsciiStrnCatS (
   // a null character.\r
   //\r
   Destination = Destination + DestLen;\r
-  while ((*Source != 0) && (SourceLen > 0)) {\r
+  while ((SourceLen > 0) && (*Source != 0)) {\r
     *(Destination++) = *(Source++);\r
     SourceLen--;\r
   }\r
@@ -2932,7 +2932,7 @@ AsciiStrToUnicodeStrS (
   // Convert string\r
   //\r
   while (*Source != '\0') {\r
-    *(Destination++) = (CHAR16)*(Source++);\r
+    *(Destination++) = (CHAR16)(UINT8)*(Source++);\r
   }\r
   *Destination = '\0';\r
 \r
@@ -3045,7 +3045,7 @@ AsciiStrnToUnicodeStrS (
   // Convert string\r
   //\r
   while ((*Source != 0) && (SourceLen > 0)) {\r
-    *(Destination++) = (CHAR16)*(Source++);\r
+    *(Destination++) = (CHAR16)(UINT8)*(Source++);\r
     SourceLen--;\r
     (*DestinationLength)++;\r
   }\r
@@ -3265,7 +3265,8 @@ AsciiStrToIpv6Address (
       &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressIndex],\r
       &LocalAddress.Addr[CompressStart],\r
       AddressIndex - CompressStart\r
-      );\r\r
+      );\r
+\r
   }\r
 \r
   if (PrefixLength != NULL) {\r