diff options
author | ydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-09-02 07:51:45 +0000 |
---|---|---|
committer | ydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-09-02 07:51:45 +0000 |
commit | 6709bbd17f09965f03fa34043923361a01ec13ed (patch) | |
tree | 7c3a4181733f5356a4351f641a4bcb1fec822f07 /MdePkg/Library/BasePrintLib | |
parent | 0c18794ea4289f03fefc7117b56740414cc0536c (diff) | |
download | edk2-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.c | 17 |
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
//
|