]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Expression.c
MdeModulePkg: Fix MSFT C4255 warning
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Expression.c
index 01e114b0e34f481d34bd832701de479080bc3660..297741c0fe9df9d031bd064e5f94e6472c7af8b3 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Utility functions for expression evaluation.\r
 \r
 /** @file\r
 Utility functions for expression evaluation.\r
 \r
-Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 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
 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
@@ -751,6 +751,7 @@ PopExpression (
 **/\r
 UINTN\r
 SaveExpressionEvaluationStackOffset (\r
 **/\r
 UINTN\r
 SaveExpressionEvaluationStackOffset (\r
+  VOID\r
   )\r
 {\r
   UINTN TempStackOffset;\r
   )\r
 {\r
   UINTN TempStackOffset;\r
@@ -1324,6 +1325,7 @@ IfrCatenate (
   UINT16         Length0;\r
   UINT16         Length1;\r
   UINT8          *TmpBuf;\r
   UINT16         Length0;\r
   UINT16         Length1;\r
   UINT8          *TmpBuf;\r
+  UINTN          MaxLen;\r
 \r
   //\r
   // String[0] - The second string\r
 \r
   //\r
   // String[0] - The second string\r
@@ -1363,10 +1365,11 @@ IfrCatenate (
 \r
   if (Value[0].Type == EFI_IFR_TYPE_STRING) {\r
     Size = StrSize (String[0]);\r
 \r
   if (Value[0].Type == EFI_IFR_TYPE_STRING) {\r
     Size = StrSize (String[0]);\r
-    StringPtr= AllocatePool (StrSize (String[1]) + Size);\r
+    MaxLen = (StrSize (String[1]) + Size) / sizeof (CHAR16);\r
+    StringPtr= AllocatePool (MaxLen * sizeof (CHAR16));\r
     ASSERT (StringPtr != NULL);\r
     ASSERT (StringPtr != NULL);\r
-    StrCpy (StringPtr, String[1]);\r
-    StrCat (StringPtr, String[0]);\r
+    StrCpyS (StringPtr, MaxLen, String[1]);\r
+    StrCatS (StringPtr, MaxLen, String[0]);\r
 \r
     Result->Type = EFI_IFR_TYPE_STRING;\r
     Result->Value.string = NewString (StringPtr, FormSet->HiiHandle);\r
 \r
     Result->Type = EFI_IFR_TYPE_STRING;\r
     Result->Value.string = NewString (StringPtr, FormSet->HiiHandle);\r
@@ -1561,12 +1564,15 @@ IfrMatch2 (
                         &BufferSize,\r
                         HandleBuffer);\r
 \r
                         &BufferSize,\r
                         HandleBuffer);\r
 \r
-  } else if (EFI_ERROR (Status)) {\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
     Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
     Status = EFI_SUCCESS;\r
     goto Done;\r
   }\r
 \r
     Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
     Status = EFI_SUCCESS;\r
     goto Done;\r
   }\r
 \r
+  ASSERT (HandleBuffer != NULL);\r
   for ( Index = 0; Index < BufferSize / sizeof(EFI_HANDLE); Index ++) {\r
     Status = gBS->HandleProtocol (\r
                   HandleBuffer[Index],\r
   for ( Index = 0; Index < BufferSize / sizeof(EFI_HANDLE); Index ++) {\r
     Status = gBS->HandleProtocol (\r
                   HandleBuffer[Index],\r
@@ -2478,7 +2484,7 @@ GetQuestionValueFromForm (
   //\r
   // Get the question value.\r
   //\r
   //\r
   // Get the question value.\r
   //\r
-  Status = GetQuestionValue(FormSet, Form, Question, GetSetValueWithHiiDriver);\r
+  Status = GetQuestionValue(FormSet, Form, Question, GetSetValueWithEditBuffer);\r
   if (EFI_ERROR (Status)) {\r
     GetTheVal = FALSE;\r
     goto Done;\r
   if (EFI_ERROR (Status)) {\r
     GetTheVal = FALSE;\r
     goto Done;\r
@@ -2824,7 +2830,7 @@ EvaluateExpression (
         if (StrPtr != NULL) {\r
           FreePool (StrPtr);\r
         }\r
         if (StrPtr != NULL) {\r
           FreePool (StrPtr);\r
         }\r
-      } else if (CompareGuid (&OpCode->Guid, &gZeroGuid) != 0) {\r
+      } else if (IsZeroGuid (&OpCode->Guid)) {\r
         if (!GetQuestionValueFromForm(NULL, FormSet->HiiHandle, &OpCode->Guid, Value->Value.u16, &QuestionVal)){\r
           Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
           break;\r
         if (!GetQuestionValueFromForm(NULL, FormSet->HiiHandle, &OpCode->Guid, Value->Value.u16, &QuestionVal)){\r
           Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
           break;\r
@@ -3131,14 +3137,21 @@ EvaluateExpression (
         case EFI_HII_VARSTORE_NAME_VALUE:\r
           if (OpCode->ValueType != EFI_IFR_TYPE_STRING) {\r
             NameValue = AllocateZeroPool ((OpCode->ValueWidth * 2 + 1) * sizeof (CHAR16));\r
         case EFI_HII_VARSTORE_NAME_VALUE:\r
           if (OpCode->ValueType != EFI_IFR_TYPE_STRING) {\r
             NameValue = AllocateZeroPool ((OpCode->ValueWidth * 2 + 1) * sizeof (CHAR16));\r
-            ASSERT (Value != NULL);\r
+            ASSERT (NameValue != NULL);\r
             //\r
             // Convert Buffer to Hex String\r
             //\r
             TempBuffer = (UINT8 *) &Value->Value + OpCode->ValueWidth - 1;\r
             StrPtr = NameValue;\r
             for (Index = 0; Index < OpCode->ValueWidth; Index ++, TempBuffer --) {\r
             //\r
             // Convert Buffer to Hex String\r
             //\r
             TempBuffer = (UINT8 *) &Value->Value + OpCode->ValueWidth - 1;\r
             StrPtr = NameValue;\r
             for (Index = 0; Index < OpCode->ValueWidth; Index ++, TempBuffer --) {\r
-              StrPtr += UnicodeValueToString (StrPtr, PREFIX_ZERO | RADIX_HEX, *TempBuffer, 2);\r
+              UnicodeValueToStringS (\r
+                StrPtr,\r
+                (OpCode->ValueWidth * 2 + 1) * sizeof (CHAR16) - ((UINTN)StrPtr - (UINTN)NameValue),\r
+                PREFIX_ZERO | RADIX_HEX,\r
+                *TempBuffer,\r
+                2\r
+                );\r
+              StrPtr += StrnLenS (StrPtr, OpCode->ValueWidth * 2 + 1 - ((UINTN)StrPtr - (UINTN)NameValue) / sizeof (CHAR16));\r
             }\r
             Status = SetValueByName (OpCode->VarStorage, OpCode->ValueName, NameValue, GetSetValueWithEditBuffer, NULL);\r
             FreePool (NameValue);\r
             }\r
             Status = SetValueByName (OpCode->VarStorage, OpCode->ValueName, NameValue, GetSetValueWithEditBuffer, NULL);\r
             FreePool (NameValue);\r
@@ -3165,7 +3178,6 @@ EvaluateExpression (
           //\r
           Status = EFI_UNSUPPORTED;\r
           goto Done;\r
           //\r
           Status = EFI_UNSUPPORTED;\r
           goto Done;\r
-          break;\r
         }\r
       } else {\r
         //\r
         }\r
       } else {\r
         //\r