From 6709bbd17f09965f03fa34043923361a01ec13ed Mon Sep 17 00:00:00 2001 From: ydong10 Date: Fri, 2 Sep 2011 07:51:45 +0000 Subject: Add check before use to make code run more safer. 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 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'MdePkg/Library') diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Library/BasePrintLib/PrintLibInternal.c index f4e8fa2d5a..aed884b176 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c @@ -843,7 +843,7 @@ BasePrintLibSPrintMarker ( // if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) { LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter); - if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { + if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter); } } @@ -851,22 +851,22 @@ BasePrintLibSPrintMarker ( if (ZeroPad) { if (Prefix != 0) { LengthToReturn += (1 * BytesPerOutputCharacter); - if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { + if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter); } } LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter); - if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { + if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, '0', BytesPerOutputCharacter); } } else { LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter); - if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { + if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Precision - Count, ' ', BytesPerOutputCharacter); } if (Prefix != 0) { LengthToReturn += (1 * BytesPerOutputCharacter); - if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { + if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, Prefix, BytesPerOutputCharacter); } } @@ -887,7 +887,7 @@ BasePrintLibSPrintMarker ( ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask; LengthToReturn += (1 * BytesPerOutputCharacter); - if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { + if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ArgumentCharacter, BytesPerOutputCharacter); } ArgumentString += BytesPerArgumentCharacter; @@ -899,7 +899,7 @@ BasePrintLibSPrintMarker ( Index++; if (Index < Count) { LengthToReturn += (1 * BytesPerOutputCharacter); - if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { + if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, 1, ',', BytesPerOutputCharacter); } } @@ -912,7 +912,7 @@ BasePrintLibSPrintMarker ( // if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) { LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter); - if ((Flags & COUNT_ONLY_NO_PRINT) == 0) { + if ((Flags & COUNT_ONLY_NO_PRINT) == 0 && Buffer != NULL) { Buffer = BasePrintLibFillBuffer (Buffer, EndBuffer, Width - Precision, ' ', BytesPerOutputCharacter); } } @@ -932,6 +932,7 @@ BasePrintLibSPrintMarker ( return (LengthToReturn / BytesPerOutputCharacter); } + ASSERT (Buffer != NULL); // // Null terminate the Unicode or ASCII string // -- cgit v1.2.3