Skip to content

Commit

Permalink
add ASSERT to 2 functions and fix issue with size difference between …
Browse files Browse the repository at this point in the history
…old and new shell versions.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9537 6f19259b-4bc3-4df7-8a09-765794883524
  • Loading branch information
jcarsey committed Dec 7, 2009
1 parent 18cefeb commit ecd3d59
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions ShellPkg/Library/UefiShellLib/UefiShellLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ STATIC EFI_SHELL_PARAMETERS_PROTOCOL *mEfiShellParametersProtocol;
STATIC EFI_HANDLE mEfiShellEnvironment2Handle;
STATIC FILE_HANDLE_FUNCTION_MAP FileFunctionMap;
STATIC UINTN mTotalParameterCount;

STATIC CHAR16 *mPostReplaceFormat;
STATIC CHAR16 *mPostReplaceFormat2;
/**
Check if a Unicode character is a hexadecimal character.
Expand Down Expand Up @@ -160,6 +161,12 @@ ShellLibConstructorWorker (
) {
EFI_STATUS Status;

ASSERT(PcdGet16 (PcdShellLibMaxPrintBufferSize) < PcdGet32 (PcdMaximumUnicodeStringLength));
mPostReplaceFormat = AllocateZeroPool (PcdGet16 (PcdShellLibMaxPrintBufferSize));
ASSERT (mPostReplaceFormat != NULL);
mPostReplaceFormat2 = AllocateZeroPool (PcdGet16 (PcdShellLibMaxPrintBufferSize));
ASSERT (mPostReplaceFormat2 != NULL);

//
// Set the parameter count to an invalid number
//
Expand Down Expand Up @@ -266,6 +273,8 @@ ShellLibConstructor (
mEfiShellParametersProtocol = NULL;
mEfiShellInterface = NULL;
mEfiShellEnvironment2Handle = NULL;
mPostReplaceFormat = NULL;
mPostReplaceFormat2 = NULL;

//
// verify that auto initialize is not set false
Expand Down Expand Up @@ -315,6 +324,16 @@ ShellLibDestructor (
mEfiShellParametersProtocol = NULL;
}
mEfiShellEnvironment2Handle = NULL;

if (mPostReplaceFormat != NULL) {
FreePool(mPostReplaceFormat);
}
if (mPostReplaceFormat2 != NULL) {
FreePool(mPostReplaceFormat2);
}
mPostReplaceFormat = NULL;
mPostReplaceFormat2 = NULL;

return (EFI_SUCCESS);
}

Expand Down Expand Up @@ -2266,6 +2285,10 @@ InternalPrintTo (
return (mEfiShellParametersProtocol->StdOut->Write(mEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));
}
if (mEfiShellInterface != NULL) {
//
// Divide in half for old shell. Must be string length not size.
//
Size /= 2;
return ( mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut, &Size, (VOID*)String));
}
ASSERT(FALSE);
Expand Down Expand Up @@ -2310,50 +2333,38 @@ InternalShellPrintWorker(
VA_LIST Marker
)
{
UINTN BufferSize;
CHAR16 *PostReplaceFormat;
CHAR16 *PostReplaceFormat2;
UINTN Return;
EFI_STATUS Status;
UINTN NormalAttribute;
CHAR16 *ResumeLocation;
CHAR16 *FormatWalker;

BufferSize = PcdGet16 (PcdShellLibMaxPrintBufferSize);
ASSERT(PcdGet16 (PcdShellLibMaxPrintBufferSize) < PcdGet32 (PcdMaximumUnicodeStringLength));
PostReplaceFormat = AllocateZeroPool (BufferSize);
ASSERT (PostReplaceFormat != NULL);
PostReplaceFormat2 = AllocateZeroPool (BufferSize);
ASSERT (PostReplaceFormat2 != NULL);

//
// Back and forth each time fixing up 1 of our flags...
//
Status = CopyReplace(Format, PostReplaceFormat, BufferSize, L"%N", L"%%N");
Status = CopyReplace(Format, mPostReplaceFormat, PcdGet16 (PcdShellLibMaxPrintBufferSize), L"%N", L"%%N");
ASSERT_EFI_ERROR(Status);
Status = CopyReplace(PostReplaceFormat, PostReplaceFormat2, BufferSize, L"%E", L"%%E");
Status = CopyReplace(mPostReplaceFormat, mPostReplaceFormat2, PcdGet16 (PcdShellLibMaxPrintBufferSize), L"%E", L"%%E");
ASSERT_EFI_ERROR(Status);
Status = CopyReplace(PostReplaceFormat2, PostReplaceFormat, BufferSize, L"%H", L"%%H");
Status = CopyReplace(mPostReplaceFormat2, mPostReplaceFormat, PcdGet16 (PcdShellLibMaxPrintBufferSize), L"%H", L"%%H");
ASSERT_EFI_ERROR(Status);
Status = CopyReplace(PostReplaceFormat, PostReplaceFormat2, BufferSize, L"%B", L"%%B");
Status = CopyReplace(mPostReplaceFormat, mPostReplaceFormat2, PcdGet16 (PcdShellLibMaxPrintBufferSize), L"%B", L"%%B");
ASSERT_EFI_ERROR(Status);
Status = CopyReplace(PostReplaceFormat2, PostReplaceFormat, BufferSize, L"%V", L"%%V");
Status = CopyReplace(mPostReplaceFormat2, mPostReplaceFormat, PcdGet16 (PcdShellLibMaxPrintBufferSize), L"%V", L"%%V");
ASSERT_EFI_ERROR(Status);

//
// Use the last buffer from replacing to print from...
//
Return = UnicodeVSPrint (PostReplaceFormat2, BufferSize, PostReplaceFormat, Marker);

FreePool(PostReplaceFormat);
Return = UnicodeVSPrint (mPostReplaceFormat2, PcdGet16 (PcdShellLibMaxPrintBufferSize), mPostReplaceFormat, Marker);

if (Col != -1 && Row != -1) {
Status = gST->ConOut->SetCursorPosition(gST->ConOut, Col, Row);
ASSERT_EFI_ERROR(Status);
}

NormalAttribute = gST->ConOut->Mode->Attribute;
FormatWalker = PostReplaceFormat2;
FormatWalker = mPostReplaceFormat2;
while (*FormatWalker != CHAR_NULL) {
//
// Find the next attribute change request
Expand Down Expand Up @@ -2410,8 +2421,6 @@ InternalShellPrintWorker(
FormatWalker = ResumeLocation + 2;
}

FreePool(PostReplaceFormat2);

return (Return);
}

Expand Down Expand Up @@ -2532,6 +2541,8 @@ ShellIsDirectory(
EFI_STATUS Status;
EFI_FILE_HANDLE Handle;

ASSERT(DirName != NULL);

Handle = NULL;

Status = ShellOpenFileByName(DirName, &Handle, EFI_FILE_MODE_READ, 0);
Expand Down Expand Up @@ -2565,6 +2576,8 @@ ShellIsFile(
EFI_STATUS Status;
EFI_FILE_HANDLE Handle;

ASSERT(Name != NULL);

Handle = NULL;

Status = ShellOpenFileByName(Name, &Handle, EFI_FILE_MODE_READ, 0);
Expand Down

0 comments on commit ecd3d59

Please sign in to comment.