-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation \r
+/**@file\r
+ This file contains the form processing code to the HII database.\r
+ \r
+Copyright (c) 2006 - 2007 Intel Corporation. <BR>\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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
\r
-Module Name:\r
-\r
- Forms.c\r
-\r
-Abstract:\r
-\r
- This file contains the form processing code to the HII database.\r
-\r
---*/\r
+**/\r
\r
\r
#include "HiiDatabase.h"\r
EFI_IFR_FORM *Form;\r
EFI_IFR_OP_HEADER *Location;\r
UINT16 *BufferLength = (UINT16 *) BufferLengthTemp;\r
+ UINTN FormLength;\r
\r
if (This == NULL) {\r
return EFI_INVALID_PARAMETER;\r
\r
PackageInstance = NULL;\r
\r
+ FormLength = 0;\r
+\r
//\r
// Check numeric value against the head of the database\r
//\r
// If we found a Form Op-code and it is of the correct Id, copy it and return\r
//\r
if (Form->FormId == FormId) {\r
- if (Location->Length > *BufferLength || Buffer == NULL) {\r
- *BufferLength = Location->Length;\r
- return EFI_BUFFER_TOO_SMALL;\r
- } else {\r
- for (; Location->OpCode != EFI_IFR_END_FORM_OP;) {\r
- CopyMem (Buffer, Location, Location->Length);\r
- Buffer = Buffer + Location->Length;\r
- Location = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
- }\r
+ //\r
+ // Calculate the total size of form\r
+ //\r
+ for (FormLength = 0; Location->OpCode != EFI_IFR_END_FORM_OP; ) {\r
+ FormLength += Location->Length;\r
+ Location = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
+ }\r
+ FormLength += Location->Length;\r
+ Location = (EFI_IFR_OP_HEADER *) ((CHAR8 *) (Location) + Location->Length);\r
\r
- CopyMem (Buffer, Location, Location->Length);\r
- return EFI_SUCCESS;\r
+ if ((Buffer == NULL) || (FormLength > *BufferLength)) {\r
+ *BufferLengthTemp = FormLength;\r
+ return EFI_BUFFER_TOO_SMALL;\r
}\r
+ \r
+ //\r
+ // Rewind to start offset of the found Form\r
+ //\r
+ Location = (EFI_IFR_OP_HEADER *) ((CHAR8 *)Location - FormLength);\r
+ CopyMem (Buffer, Location, FormLength);\r
+ return EFI_SUCCESS;\r
}\r
\r
default:\r
}\r
}\r
\r
- return EFI_SUCCESS;\r
+ return EFI_NOT_FOUND;\r
}\r
\r
//\r