]> 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 68c33e9b7b1f1fd550244c3365be9cc17f1a9141..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
@@ -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
@@ -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
@@ -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
@@ -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