]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePrintLib/PrintLibInternal.c
MdePkg/BasePrintLib: Do not do operations with NULL
[mirror_edk2.git] / MdePkg / Library / BasePrintLib / PrintLibInternal.c
index c4fd755eec029a4bd02f717c0bddc44a1992041e..e61aed9fda649c9ed279445b22d15c0961b4eb6e 100644 (file)
@@ -373,17 +373,21 @@ BasePrintLibSPrintMarker (
   }\r
 \r
   LengthToReturn = 0;\r
+  EndBuffer = NULL;\r
+  OriginalBuffer = NULL;\r
 \r
   //\r
   // Reserve space for the Null terminator.\r
   //\r
-  BufferSize--;\r
-  OriginalBuffer = Buffer;\r
+  if (Buffer != NULL) {\r
+    BufferSize--;\r
+    OriginalBuffer = Buffer;\r
 \r
-  //\r
-  // Set the tag for the end of the input Buffer.\r
-  //\r
-  EndBuffer      = Buffer + BufferSize * BytesPerOutputCharacter;\r
+    //\r
+    // Set the tag for the end of the input Buffer.\r
+    //\r
+    EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter;\r
+  }\r
 \r
   if ((Flags & FORMAT_UNICODE) != 0) {\r
     //\r
@@ -411,7 +415,10 @@ BasePrintLibSPrintMarker (
   //\r
   // Loop until the end of the format string is reached or the output buffer is full\r
   //\r
-  while (FormatCharacter != 0 && Buffer < EndBuffer) {\r
+  while (FormatCharacter != 0) {\r
+    if ((Buffer != NULL) && (Buffer >= EndBuffer)) {\r
+      break;\r
+    }\r
     //\r
     // Clear all the flag bits except those that may have been passed in\r
     //\r