]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Expression.c
1. Update SetupBrowser to pass correct buffer value for OrderedList Callback
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Expression.c
index 25d4e0a678f2fc439de691dacf01465a9be9b774..3f810323dba9ff6ad7ef69420801a3662e3b5918 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Utility functions for expression evaluation.\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+Copyright (c) 2007 - 2008, Intel Corporation\r
 All rights reserved. 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
@@ -79,7 +79,7 @@ GrowStack (
     //\r
     // Free The Old Stack\r
     //\r
-    gBS->FreePool (*Stack);\r
+    FreePool (*Stack);\r
   }\r
 \r
   //\r
@@ -421,6 +421,14 @@ IdToQuestion (
 \r
     Question = IdToQuestion2 (Form, QuestionId);\r
     if (Question != NULL) {\r
+      //\r
+      // EFI variable storage may be updated by Callback() asynchronous,\r
+      // to keep synchronous, always reload the Question Value.\r
+      //\r
+      if (Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
+        GetQuestionValue (FormSet, Form, Question, FALSE);\r
+      }\r
+\r
       return Question;\r
     }\r
 \r
@@ -504,7 +512,7 @@ InitializeUnicodeCollationProtocol (
 **/\r
 VOID\r
 IfrStrToUpper (\r
-  CHAR16                   *String\r
+  IN CHAR16                   *String\r
   )\r
 {\r
   while (*String != 0) {\r
@@ -611,7 +619,6 @@ IfrToUint (
   EFI_HII_VALUE  Value;\r
   CHAR16         *String;\r
   CHAR16         *StringPtr;\r
-  UINTN          BufferSize;\r
 \r
   Status = PopExpression (&Value);\r
   if (EFI_ERROR (Status)) {\r
@@ -635,14 +642,14 @@ IfrToUint (
       //\r
       // Hex string\r
       //\r
-      BufferSize = sizeof (UINT64);\r
-      Status = HexStringToBuf ((UINT8 *) &Result->Value.u64, &BufferSize, StringPtr + 2, NULL);\r
+      Result->Value.u64 = StrHexToUint64 (String);\r
     } else {\r
       //\r
-      // BUGBUG: Need handle decimal string\r
+      // decimal string\r
       //\r
+      Result->Value.u64 = StrDecimalToUint64 (String);\r
     }\r
-    gBS->FreePool (String);\r
+    FreePool (String);\r
   } else {\r
     CopyMem (Result, &Value, sizeof (EFI_HII_VALUE));\r
   }\r
@@ -696,7 +703,7 @@ IfrCatenate (
     }\r
 \r
     String[Index] = GetToken (Value.Value.string, FormSet->HiiHandle);\r
-    if (String== NULL) {\r
+    if (String[Index] == NULL) {\r
       Status = EFI_NOT_FOUND;\r
       goto Done;\r
     }\r
@@ -712,9 +719,15 @@ IfrCatenate (
   Result->Value.string = NewString (StringPtr, FormSet->HiiHandle);\r
 \r
 Done:\r
-  SafeFreePool (String[0]);\r
-  SafeFreePool (String[1]);\r
-  SafeFreePool (StringPtr);\r
+  if (String[0] != NULL) {\r
+    FreePool (String[0]);\r
+  }\r
+  if (String[1] != NULL) {\r
+    FreePool (String[1]);\r
+  }\r
+  if (StringPtr != NULL) {\r
+    FreePool (StringPtr);\r
+  }\r
 \r
   return Status;\r
 }\r
@@ -760,7 +773,7 @@ IfrMatch (
     }\r
 \r
     String[Index] = GetToken (Value.Value.string, FormSet->HiiHandle);\r
-    if (String== NULL) {\r
+    if (String [Index] == NULL) {\r
       Status = EFI_NOT_FOUND;\r
       goto Done;\r
     }\r
@@ -770,8 +783,12 @@ IfrMatch (
   Result->Value.b = mUnicodeCollation->MetaiMatch (mUnicodeCollation, String[0], String[1]);\r
 \r
 Done:\r
-  SafeFreePool (String[0]);\r
-  SafeFreePool (String[1]);\r
+  if (String[0] != NULL) {\r
+    FreePool (String[0]);\r
+  }\r
+  if (String[1] != NULL) {\r
+    FreePool (String[1]);\r
+  }\r
 \r
   return Status;\r
 }\r
@@ -833,7 +850,7 @@ IfrFind (
     }\r
 \r
     String[Index] = GetToken (Value.Value.string, FormSet->HiiHandle);\r
-    if (String== NULL) {\r
+    if (String[Index] == NULL) {\r
       Status = EFI_NOT_FOUND;\r
       goto Done;\r
     }\r
@@ -855,8 +872,12 @@ IfrFind (
   }\r
 \r
 Done:\r
-  SafeFreePool (String[0]);\r
-  SafeFreePool (String[1]);\r
+  if (String[0] != NULL) {\r
+    FreePool (String[0]);\r
+  }\r
+  if (String[1] != NULL) {\r
+    FreePool (String[1]);\r
+  }\r
 \r
   return Status;\r
 }\r
@@ -927,7 +948,7 @@ IfrMid (
   Result->Type = EFI_IFR_TYPE_STRING;\r
   Result->Value.string = NewString (SubString, FormSet->HiiHandle);\r
 \r
-  gBS->FreePool (String);\r
+  FreePool (String);\r
 \r
   return Status;\r
 }\r
@@ -985,7 +1006,7 @@ IfrToken (
     }\r
 \r
     String[Index] = GetToken (Value.Value.string, FormSet->HiiHandle);\r
-    if (String== NULL) {\r
+    if (String[Index] == NULL) {\r
       Status = EFI_NOT_FOUND;\r
       goto Done;\r
     }\r
@@ -1025,8 +1046,12 @@ IfrToken (
   Result->Value.string = NewString (SubString, FormSet->HiiHandle);\r
 \r
 Done:\r
-  SafeFreePool (String[0]);\r
-  SafeFreePool (String[1]);\r
+  if (String[0] != NULL) {\r
+    FreePool (String[0]);\r
+  }\r
+  if (String[1] != NULL) {\r
+    FreePool (String[1]);\r
+  }\r
 \r
   return Status;\r
 }\r
@@ -1086,7 +1111,7 @@ IfrSpan (
     }\r
 \r
     String[Index] = GetToken (Value.Value.string, FormSet->HiiHandle);\r
-    if (String== NULL) {\r
+    if (String [Index] == NULL) {\r
       Status = EFI_NOT_FOUND;\r
       goto Done;\r
     }\r
@@ -1129,8 +1154,12 @@ IfrSpan (
   Result->Value.u64 = StringPtr - String[1];\r
 \r
 Done:\r
-  SafeFreePool (String[0]);\r
-  SafeFreePool (String[1]);\r
+  if (String[0] != NULL) {\r
+    FreePool (String[0]);\r
+  }\r
+  if (String[1] != NULL) {\r
+    FreePool (String[1]);\r
+  }\r
 \r
   return Status;\r
 }\r
@@ -1241,14 +1270,14 @@ CompareHiiValue (
 \r
     Str2 = GetToken (Value2->Value.string, HiiHandle);\r
     if (Str2 == NULL) {\r
-      gBS->FreePool (Str1);\r
+      FreePool (Str1);\r
       return EFI_INVALID_PARAMETER;\r
     }\r
 \r
     Result = StrCmp (Str1, Str2);\r
 \r
-    gBS->FreePool (Str1);\r
-    gBS->FreePool (Str2);\r
+    FreePool (Str1);\r
+    FreePool (Str2);\r
 \r
     return Result;\r
   }\r
@@ -1270,7 +1299,9 @@ CompareHiiValue (
 \r
 \r
 /**\r
-  Evaluate the result of a HII expression\r
+  Evaluate the result of a HII expression.\r
+\r
+  If Expression is NULL, then ASSERT.\r
 \r
   @param  FormSet                FormSet associated with this expression.\r
   @param  Form                   Form associated with this expression.\r
@@ -1312,6 +1343,7 @@ EvaluateExpression (
   //\r
   ResetExpressionStack ();\r
 \r
+  ASSERT (Expression != NULL);\r
   Expression->Result.Type = EFI_IFR_TYPE_OTHER;\r
 \r
   Link = GetFirstNode (&Expression->OpCodeListHead);\r
@@ -1495,7 +1527,7 @@ EvaluateExpression (
 \r
       Value->Type = EFI_IFR_TYPE_NUM_SIZE_64;\r
       Value->Value.u64 = StrLen (StrPtr);\r
-      gBS->FreePool (StrPtr);\r
+      FreePool (StrPtr);\r
       break;\r
 \r
     case EFI_IFR_NOT_OP:\r
@@ -1559,7 +1591,7 @@ EvaluateExpression (
       } else {\r
         Index = (UINT16) Value->Value.u64;\r
         Value->Value.string = Index;\r
-        gBS->FreePool (StrPtr);\r
+        FreePool (StrPtr);\r
       }\r
       break;\r
 \r
@@ -1599,7 +1631,7 @@ EvaluateExpression (
         } else {\r
           Value->Value.b = FALSE;\r
         }\r
-        gBS->FreePool (StrPtr);\r
+        FreePool (StrPtr);\r
         Value->Type = EFI_IFR_TYPE_BOOLEAN;\r
       }\r
       break;\r
@@ -1639,7 +1671,7 @@ EvaluateExpression (
         mUnicodeCollation->StrUpr (mUnicodeCollation, StrPtr);\r
       }\r
       Value->Value.string = NewString (StrPtr, FormSet->HiiHandle);\r
-      gBS->FreePool (StrPtr);\r
+      FreePool (StrPtr);\r
       break;\r
 \r
     case EFI_IFR_BITWISE_NOT_OP:\r