]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/DisplayEngineDxe/InputHandler.c
MdeModulePkg DxeCore: Fix issue to print GUID value %g without pointer
[mirror_edk2.git] / MdeModulePkg / Universal / DisplayEngineDxe / InputHandler.c
index a0b87ff7be4157c2d50c07b58582c1b0e9ffe375..d02c0bf0742433ef5f0ba2187dad22a410539848 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Implementation for handling user input from the User Interfaces.\r
 \r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -84,6 +84,7 @@ ReadString (
   UINTN                   Maximum;\r
   FORM_DISPLAY_ENGINE_STATEMENT  *Question;\r
   BOOLEAN                 IsPassword;\r
+  UINTN                   MaxLen;\r
 \r
   DimensionsWidth  = gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn;\r
   DimensionsHeight = gStatementDimensions.BottomRow - gStatementDimensions.TopRow;\r
@@ -102,7 +103,8 @@ ReadString (
     IsPassword = FALSE;\r
   }\r
 \r
-  TempString = AllocateZeroPool ((Maximum + 1)* sizeof (CHAR16));\r
+  MaxLen = Maximum + 1;\r
+  TempString = AllocateZeroPool (MaxLen * sizeof (CHAR16));\r
   ASSERT (TempString);\r
 \r
   if (ScreenSize < (Maximum + 1)) {\r
@@ -227,7 +229,6 @@ ReadString (
         return EFI_DEVICE_ERROR;\r
       }\r
 \r
-      break;\r
 \r
     case CHAR_BACKSPACE:\r
       if (StringPtr[0] != CHAR_NULL && CurrentCursor != 0) {\r
@@ -244,7 +245,7 @@ ReadString (
         //\r
         // Effectively truncate string by 1 character\r
         //\r
-        StrCpy (StringPtr, TempString);\r
+        StrCpyS (StringPtr, MaxLen, TempString);\r
         CurrentCursor --;\r
       }\r
 \r
@@ -253,7 +254,7 @@ ReadString (
       // If it is the beginning of the string, don't worry about checking maximum limits\r
       //\r
       if ((StringPtr[0] == CHAR_NULL) && (Key.UnicodeChar != CHAR_BACKSPACE)) {\r
-        StrnCpy (StringPtr, &Key.UnicodeChar, 1);\r
+        StrnCpyS (StringPtr, MaxLen, &Key.UnicodeChar, 1);\r
         CurrentCursor++;\r
       } else if ((GetStringWidth (StringPtr) < ((Maximum + 1) * sizeof (CHAR16))) && (Key.UnicodeChar != CHAR_BACKSPACE)) {\r
         KeyPad[0] = Key.UnicodeChar;\r
@@ -264,11 +265,11 @@ ReadString (
             TempString[Index] = StringPtr[Index];\r
           }\r
                  TempString[Index] = CHAR_NULL;\r
-          StrCat (TempString, KeyPad);\r
-          StrCat (TempString, StringPtr + CurrentCursor);\r
-          StrCpy (StringPtr, TempString);\r
+          StrCatS (TempString, MaxLen, KeyPad);\r
+          StrCatS (TempString, MaxLen, StringPtr + CurrentCursor);\r
+          StrCpyS (StringPtr, MaxLen, TempString);\r
         } else {\r
-          StrCat (StringPtr, KeyPad);\r
+          StrCatS (StringPtr, MaxLen, KeyPad);\r
         }\r
         CurrentCursor++;\r
       }\r
@@ -523,6 +524,7 @@ GetNumericInput (
 \r
   Question      = MenuOption->ThisTag;\r
   QuestionValue = &Question->CurrentValue;\r
+  ZeroMem (InputText, MAX_NUMERIC_INPUT_WIDTH * sizeof (CHAR16));\r
 \r
   //\r
   // Only two case, user can enter to this function: Enter and +/- case.\r
@@ -689,16 +691,17 @@ GetNumericInput (
       if (MenuOption->Sequence == 0) {\r
         InputText[0] = LEFT_NUMERIC_DELIMITER;\r
         SetUnicodeMem (InputText + 1, InputWidth, L' ');\r
-      } else {\r
+        InputText[InputWidth + 1] = DATE_SEPARATOR;\r
+        InputText[InputWidth + 2] = L'\0';\r
+      } else  if (MenuOption->Sequence == 1){\r
         SetUnicodeMem (InputText, InputWidth, L' ');\r
-      }\r
-\r
-      if (MenuOption->Sequence == 2) {\r
-        InputText[InputWidth + 1] = RIGHT_NUMERIC_DELIMITER;\r
+        InputText[InputWidth] = DATE_SEPARATOR;\r
+        InputText[InputWidth + 1] = L'\0';\r
       } else {\r
-        InputText[InputWidth + 1] = DATE_SEPARATOR;\r
+        SetUnicodeMem (InputText, InputWidth, L' ');\r
+        InputText[InputWidth] = RIGHT_NUMERIC_DELIMITER;\r
+        InputText[InputWidth + 1] = L'\0';\r
       }\r
-      InputText[InputWidth + 2] = L'\0';\r
 \r
       PrintStringAt (Column, Row, InputText);\r
       if (MenuOption->Sequence == 0) {\r
@@ -712,16 +715,17 @@ GetNumericInput (
       if (MenuOption->Sequence == 0) {\r
         InputText[0] = LEFT_NUMERIC_DELIMITER;\r
         SetUnicodeMem (InputText + 1, InputWidth, L' ');\r
-      } else {\r
+        InputText[InputWidth + 1] = TIME_SEPARATOR;\r
+        InputText[InputWidth + 2] = L'\0';\r
+      } else if (MenuOption->Sequence == 1){\r
         SetUnicodeMem (InputText, InputWidth, L' ');\r
-      }\r
-\r
-      if (MenuOption->Sequence == 2) {\r
-        InputText[InputWidth + 1] = RIGHT_NUMERIC_DELIMITER;\r
+        InputText[InputWidth] = TIME_SEPARATOR;\r
+        InputText[InputWidth + 1] = L'\0';\r
       } else {\r
-        InputText[InputWidth + 1] = TIME_SEPARATOR;\r
+        SetUnicodeMem (InputText, InputWidth, L' ');\r
+        InputText[InputWidth] = RIGHT_NUMERIC_DELIMITER;\r
+        InputText[InputWidth + 1] = L'\0';\r
       }\r
-      InputText[InputWidth + 2] = L'\0';\r
 \r
       PrintStringAt (Column, Row, InputText);\r
       if (MenuOption->Sequence == 0) {\r
@@ -879,7 +883,6 @@ TheKey2:
         }\r
 \r
         goto EnterCarriageReturn;\r
-        break;\r
 \r
       case SCAN_UP:\r
       case SCAN_DOWN:\r
@@ -980,7 +983,6 @@ EnterCarriageReturn:
       }\r
 \r
       return EFI_SUCCESS;\r
-      break;\r
 \r
     case CHAR_BACKSPACE:\r
       if (ManualInput) {\r
@@ -1071,14 +1073,14 @@ EnterCarriageReturn:
 \r
           if (ValidateFail) {\r
             UpdateStatusBar (INPUT_ERROR, TRUE);\r
-            ASSERT (Count < sizeof (PreviousNumber) / sizeof (PreviousNumber[0]));\r
+            ASSERT (Count < ARRAY_SIZE (PreviousNumber));\r
             EditValue = PreviousNumber[Count];\r
             break;\r
           }\r
         } else {\r
           if (EditValue > Maximum) {\r
             UpdateStatusBar (INPUT_ERROR, TRUE);\r
-            ASSERT (Count < sizeof (PreviousNumber) / sizeof (PreviousNumber[0]));\r
+            ASSERT (Count < ARRAY_SIZE (PreviousNumber));\r
             EditValue = PreviousNumber[Count];\r
             break;\r
           }\r
@@ -1087,7 +1089,7 @@ EnterCarriageReturn:
         UpdateStatusBar (INPUT_ERROR, FALSE);\r
 \r
         Count++;\r
-        ASSERT (Count < (sizeof (PreviousNumber) / sizeof (PreviousNumber[0])));\r
+        ASSERT (Count < (ARRAY_SIZE (PreviousNumber)));\r
         PreviousNumber[Count] = EditValue;\r
 \r
         gST->ConOut->SetAttribute (gST->ConOut, GetHighlightTextColor ());\r
@@ -1300,9 +1302,6 @@ GetSelectionInputPopUp (
   ShowDownArrow     = FALSE;\r
   ShowUpArrow       = FALSE;\r
 \r
-  StringPtr = AllocateZeroPool ((gOptionBlockWidth + 1) * 2);\r
-  ASSERT (StringPtr);\r
-\r
   ZeroMem (&HiiValue, sizeof (EFI_HII_VALUE));\r
 \r
   Question = MenuOption->ThisTag;\r
@@ -1447,7 +1446,7 @@ GetSelectionInputPopUp (
         CopyMem (TempStringPtr, StringPtr, (sizeof (CHAR16) * (PopUpWidth - 5)));\r
         FreePool (StringPtr);\r
         StringPtr = TempStringPtr;\r
-        StrCat (StringPtr, L"...");\r
+        StrCatS (StringPtr, PopUpWidth - 1, L"...");\r
       }\r
 \r
       if (Index == HighlightOptionIndex) {\r