]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePrintLib/PrintLibInternal.c
MdePkg BaseStackCheckLib: Correct style of file header
[mirror_edk2.git] / MdePkg / Library / BasePrintLib / PrintLibInternal.c
index cec5b3bc994b20101efb9b68d20759100e940227..6f19b314496b4b190df386697d5e53fc5fda6080 100644 (file)
@@ -1107,7 +1107,12 @@ BasePrintLibSPrintMarker (
       // Compute the number of characters in ArgumentString and store it in Count\r
       // ArgumentString is either null-terminated, or it contains Precision characters\r
       //\r
-      for (Count = 0; Count < Precision || ((Flags & PRECISION) == 0); Count++) {\r
+      for (Count = 0;\r
+            (ArgumentString[Count * BytesPerArgumentCharacter] != '\0' ||\r
+             (BytesPerArgumentCharacter > 1 &&\r
+              ArgumentString[Count * BytesPerArgumentCharacter + 1]!= '\0')) &&\r
+            (Count < Precision || ((Flags & PRECISION) == 0));\r
+              Count++) {\r
         ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;\r
         if (ArgumentCharacter == 0) {\r
           break;\r
@@ -1164,8 +1169,10 @@ BasePrintLibSPrintMarker (
     //\r
     // Copy the string into the output buffer performing the required type conversions\r
     //\r
-    while (Index < Count) {\r
-      ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;\r
+    while (Index < Count &&\r
+           (ArgumentString[0] != '\0' ||\r
+            (BytesPerArgumentCharacter > 1 && ArgumentString[1] != '\0'))) {\r
+      ArgumentCharacter = ((*ArgumentString & 0xff) | (((UINT8)*(ArgumentString + 1)) << 8)) & ArgumentMask;\r
 \r
       LengthToReturn += (1 * BytesPerOutputCharacter);\r
       if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r