]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add check before use to make code run more safer.
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 2 Sep 2011 07:51:45 +0000 (07:51 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 2 Sep 2011 07:51:45 +0000 (07:51 +0000)
Signed-off-by: ydong10
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12262 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/BasePrintLib/PrintLibInternal.c

index f4e8fa2d5adf398ed805283b8aa1fe08f5cf86e7..aed884b176ade48f2e0b74dce7a917b05ddf33ed 100644 (file)
@@ -843,7 +843,7 @@ BasePrintLibSPrintMarker (
     //\r
     if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {\r
       LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);\r
-      if ((Flags & COUNT_ONLY_NO_PRINT) == 0) {\r
+      if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
         Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
       }\r
     }\r
@@ -851,22 +851,22 @@ BasePrintLibSPrintMarker (
     if (ZeroPad) {\r
       if (Prefix != 0) {\r
         LengthToReturn += (1 * BytesPerOutputCharacter);\r
-        if ((Flags & COUNT_ONLY_NO_PRINT) == 0) {\r
+        if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
           Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);\r
         }\r
       }\r
       LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);\r
-      if ((Flags & COUNT_ONLY_NO_PRINT) == 0) {\r
+      if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
         Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter);\r
       }\r
     } else {\r
       LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);\r
-      if ((Flags & COUNT_ONLY_NO_PRINT) == 0) {\r
+      if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
         Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter);\r
       }\r
       if (Prefix != 0) {\r
         LengthToReturn += (1 * BytesPerOutputCharacter);\r
-        if ((Flags & COUNT_ONLY_NO_PRINT) == 0) {\r
+        if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
           Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter);\r
         }\r
       }\r
@@ -887,7 +887,7 @@ BasePrintLibSPrintMarker (
       ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;\r
 \r
       LengthToReturn += (1 * BytesPerOutputCharacter);\r
-      if ((Flags & COUNT_ONLY_NO_PRINT) == 0) {\r
+      if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
         Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter);\r
       }\r
       ArgumentString    += BytesPerArgumentCharacter;\r
@@ -899,7 +899,7 @@ BasePrintLibSPrintMarker (
           Index++;\r
           if (Index < Count) {\r
             LengthToReturn += (1 * BytesPerOutputCharacter);\r
-            if ((Flags & COUNT_ONLY_NO_PRINT) == 0) {\r
+            if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
               Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter);\r
             }\r
           }\r
@@ -912,7 +912,7 @@ BasePrintLibSPrintMarker (
     //\r
     if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {\r
       LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);\r
-      if ((Flags & COUNT_ONLY_NO_PRINT) == 0) {\r
+      if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) {\r
         Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
       }\r
     }\r
@@ -932,6 +932,7 @@ BasePrintLibSPrintMarker (
     return (LengthToReturn / BytesPerOutputCharacter);\r
   }\r
 \r
+  ASSERT (Buffer != NULL);\r
   //\r
   // Null terminate the Unicode or ASCII string\r
   //\r