summaryrefslogtreecommitdiff
path: root/MdePkg/Library/BasePrintLib
diff options
context:
space:
mode:
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>2011-09-02 07:51:45 +0000
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>2011-09-02 07:51:45 +0000
commit6709bbd17f09965f03fa34043923361a01ec13ed (patch)
tree7c3a4181733f5356a4351f641a4bcb1fec822f07 /MdePkg/Library/BasePrintLib
parent0c18794ea4289f03fefc7117b56740414cc0536c (diff)
downloadedk2-platforms-6709bbd17f09965f03fa34043923361a01ec13ed.tar.xz
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
Diffstat (limited to 'MdePkg/Library/BasePrintLib')
-rw-r--r--MdePkg/Library/BasePrintLib/PrintLibInternal.c17
1 files changed, 9 insertions, 8 deletions
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
//