]> git.proxmox.com Git - mirror_edk2.git/commitdiff
add ASSERT to 2 functions and fix issue with size difference between old and new...
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 7 Dec 2009 18:05:00 +0000 (18:05 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 7 Dec 2009 18:05:00 +0000 (18:05 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9537 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLib/UefiShellLib.c

index 020d6c560d435da186ba98afac02197f2c775c38..fb763bde6162bc81f0e9514d4ca76912513d5b19 100644 (file)
@@ -54,7 +54,8 @@ STATIC EFI_SHELL_PARAMETERS_PROTOCOL *mEfiShellParametersProtocol;
 STATIC EFI_HANDLE                    mEfiShellEnvironment2Handle;\r
 STATIC FILE_HANDLE_FUNCTION_MAP      FileFunctionMap;\r
 STATIC UINTN                         mTotalParameterCount;\r
-\r
+STATIC CHAR16                        *mPostReplaceFormat;\r
+STATIC CHAR16                        *mPostReplaceFormat2;\r
 /**\r
   Check if a Unicode character is a hexadecimal character.\r
 \r
@@ -160,6 +161,12 @@ ShellLibConstructorWorker (
   ) {\r
   EFI_STATUS Status;\r
 \r
+  ASSERT(PcdGet16 (PcdShellLibMaxPrintBufferSize) < PcdGet32 (PcdMaximumUnicodeStringLength));\r
+  mPostReplaceFormat = AllocateZeroPool (PcdGet16 (PcdShellLibMaxPrintBufferSize));\r
+  ASSERT (mPostReplaceFormat != NULL);\r
+  mPostReplaceFormat2 = AllocateZeroPool (PcdGet16 (PcdShellLibMaxPrintBufferSize));\r
+  ASSERT (mPostReplaceFormat2 != NULL);\r
+\r
   //\r
   // Set the parameter count to an invalid number\r
   //\r
@@ -266,6 +273,8 @@ ShellLibConstructor (
   mEfiShellParametersProtocol = NULL;\r
   mEfiShellInterface          = NULL;\r
   mEfiShellEnvironment2Handle = NULL;\r
+  mPostReplaceFormat          = NULL;\r
+  mPostReplaceFormat2         = NULL;\r
 \r
   //\r
   // verify that auto initialize is not set false\r
@@ -315,6 +324,16 @@ ShellLibDestructor (
     mEfiShellParametersProtocol = NULL;\r
   }\r
   mEfiShellEnvironment2Handle = NULL;\r
+\r
+  if (mPostReplaceFormat != NULL) {\r
+    FreePool(mPostReplaceFormat);\r
+  }\r
+  if (mPostReplaceFormat2 != NULL) {\r
+    FreePool(mPostReplaceFormat2);\r
+  }\r
+  mPostReplaceFormat          = NULL;\r
+  mPostReplaceFormat2         = NULL;\r
+\r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -2266,6 +2285,10 @@ InternalPrintTo (
     return (mEfiShellParametersProtocol->StdOut->Write(mEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));\r
   }\r
   if (mEfiShellInterface          != NULL) {\r
+    //\r
+    // Divide in half for old shell.  Must be string length not size.\r
+    //\r
+    Size /= 2;\r
     return (         mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut,          &Size, (VOID*)String));\r
   }\r
   ASSERT(FALSE);\r
@@ -2310,42 +2333,30 @@ InternalShellPrintWorker(
   VA_LIST                 Marker\r
   ) \r
 {\r
-  UINTN             BufferSize;\r
-  CHAR16            *PostReplaceFormat;\r
-  CHAR16            *PostReplaceFormat2;\r
   UINTN             Return;\r
   EFI_STATUS        Status;\r
   UINTN             NormalAttribute;\r
   CHAR16            *ResumeLocation;\r
   CHAR16            *FormatWalker;\r
   \r
-  BufferSize = PcdGet16 (PcdShellLibMaxPrintBufferSize);\r
-  ASSERT(PcdGet16 (PcdShellLibMaxPrintBufferSize) < PcdGet32 (PcdMaximumUnicodeStringLength));\r
-  PostReplaceFormat = AllocateZeroPool (BufferSize);\r
-  ASSERT (PostReplaceFormat != NULL);\r
-  PostReplaceFormat2 = AllocateZeroPool (BufferSize);\r
-  ASSERT (PostReplaceFormat2 != NULL);\r
-\r
   //\r
   // Back and forth each time fixing up 1 of our flags...\r
   //\r
-  Status = CopyReplace(Format,             PostReplaceFormat,  BufferSize, L"%N", L"%%N");\r
+  Status = CopyReplace(Format,             mPostReplaceFormat,  PcdGet16 (PcdShellLibMaxPrintBufferSize), L"%N", L"%%N");\r
   ASSERT_EFI_ERROR(Status);\r
-  Status = CopyReplace(PostReplaceFormat,  PostReplaceFormat2, BufferSize, L"%E", L"%%E");\r
+  Status = CopyReplace(mPostReplaceFormat,  mPostReplaceFormat2, PcdGet16 (PcdShellLibMaxPrintBufferSize), L"%E", L"%%E");\r
   ASSERT_EFI_ERROR(Status);\r
-  Status = CopyReplace(PostReplaceFormat2, PostReplaceFormat,  BufferSize, L"%H", L"%%H");\r
+  Status = CopyReplace(mPostReplaceFormat2, mPostReplaceFormat,  PcdGet16 (PcdShellLibMaxPrintBufferSize), L"%H", L"%%H");\r
   ASSERT_EFI_ERROR(Status);\r
-  Status = CopyReplace(PostReplaceFormat,  PostReplaceFormat2, BufferSize, L"%B", L"%%B");\r
+  Status = CopyReplace(mPostReplaceFormat,  mPostReplaceFormat2, PcdGet16 (PcdShellLibMaxPrintBufferSize), L"%B", L"%%B");\r
   ASSERT_EFI_ERROR(Status);\r
-  Status = CopyReplace(PostReplaceFormat2, PostReplaceFormat,  BufferSize, L"%V", L"%%V");\r
+  Status = CopyReplace(mPostReplaceFormat2, mPostReplaceFormat,  PcdGet16 (PcdShellLibMaxPrintBufferSize), L"%V", L"%%V");\r
   ASSERT_EFI_ERROR(Status);\r
 \r
   //\r
   // Use the last buffer from replacing to print from...\r
   //\r
-  Return = UnicodeVSPrint (PostReplaceFormat2, BufferSize, PostReplaceFormat, Marker);\r
-\r
-  FreePool(PostReplaceFormat);\r
+  Return = UnicodeVSPrint (mPostReplaceFormat2, PcdGet16 (PcdShellLibMaxPrintBufferSize), mPostReplaceFormat, Marker);\r
 \r
   if (Col != -1 && Row != -1) {\r
     Status = gST->ConOut->SetCursorPosition(gST->ConOut, Col, Row);\r
@@ -2353,7 +2364,7 @@ InternalShellPrintWorker(
   }\r
 \r
   NormalAttribute = gST->ConOut->Mode->Attribute;\r
-  FormatWalker = PostReplaceFormat2;\r
+  FormatWalker = mPostReplaceFormat2;\r
   while (*FormatWalker != CHAR_NULL) {\r
     //\r
     // Find the next attribute change request\r
@@ -2410,8 +2421,6 @@ InternalShellPrintWorker(
     FormatWalker = ResumeLocation + 2;\r
   }\r
 \r
-  FreePool(PostReplaceFormat2);\r
-\r
   return (Return);\r
 }\r
 \r
@@ -2532,6 +2541,8 @@ ShellIsDirectory(
   EFI_STATUS        Status;\r
   EFI_FILE_HANDLE   Handle;\r
 \r
+  ASSERT(DirName != NULL);\r
+\r
   Handle = NULL;\r
 \r
   Status = ShellOpenFileByName(DirName, &Handle, EFI_FILE_MODE_READ, 0);\r
@@ -2565,6 +2576,8 @@ ShellIsFile(
   EFI_STATUS        Status;\r
   EFI_FILE_HANDLE   Handle;\r
 \r
+  ASSERT(Name != NULL);\r
+\r
   Handle = NULL;\r
 \r
   Status = ShellOpenFileByName(Name, &Handle, EFI_FILE_MODE_READ, 0);\r