IN OUT VOID **Buffer\r
)\r
{\r
- UINTN NewSize;\r
- UINTN OldSize;\r
VOID *Ptr;\r
\r
//\r
// copy the old buffer's content to the new-size buffer,\r
// then free the old buffer.\r
//\r
- OldSize = *Count * SizeOfCount;\r
*Count += CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT;\r
- NewSize = *Count * SizeOfCount;\r
-\r
- Ptr = AllocateZeroPool (NewSize);\r
+ Ptr = ReallocatePool (\r
+ SizeOfCount * ((*Count) - CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT), \r
+ SizeOfCount * (*Count),\r
+ *Buffer\r
+ );\r
if (Ptr == NULL) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r
-\r
- CopyMem (Ptr, *Buffer, OldSize);\r
-\r
- if (*Buffer != NULL) {\r
- FreePool (*Buffer);\r
- }\r
-\r
*Buffer = Ptr;\r
-\r
return EFI_SUCCESS;\r
}\r
\r
\r
#include "DevicePath.h"\r
\r
-/**\r
- Adjusts the size of a previously allocated buffer.\r
-\r
- @param OldPool A pointer to the buffer whose size is being adjusted.\r
- @param OldSize The size of the current buffer.\r
- @param NewSize The size of the new buffer.\r
-\r
- @return A pointer to the new buffer or NULL if allocation fails.\r
-\r
-**/\r
-VOID *\r
-ReallocatePool (\r
- IN VOID *OldPool,\r
- IN UINTN OldSize,\r
- IN UINTN NewSize\r
- )\r
-{\r
- VOID *NewPool;\r
-\r
- NewPool = NULL;\r
- if (NewSize != 0) {\r
- NewPool = AllocateZeroPool (NewSize);\r
- }\r
-\r
- if (OldPool != NULL) {\r
- if (NewPool != NULL) {\r
- CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);\r
- }\r
-\r
- FreePool (OldPool);\r
- }\r
-\r
- return NewPool;\r
-}\r
-\r
/**\r
Concatenates a formatted unicode string to allocated pool. The caller must\r
free the resulting buffer.\r
Size = StrSize (AppendStr) - sizeof (UINT16);\r
Size = Size + StrSize (Str->Str);\r
Str->Str = ReallocatePool (\r
- Str->Str,\r
StrSize (Str->Str),\r
- Size\r
+ Size,\r
+ Str->Str\r
);\r
ASSERT (Str->Str != NULL);\r
}\r
// Shrink pool used for string allocation\r
//\r
NewSize = (Str.Len + 1) * sizeof (CHAR16);\r
- Str.Str = ReallocatePool (Str.Str, NewSize, NewSize);\r
+ Str.Str = ReallocatePool (NewSize, NewSize, Str.Str);\r
ASSERT (Str.Str != NULL);\r
Str.Str[Str.Len] = 0;\r
return Str.Str;\r
}\r
\r
NewSize = (Str.Len + 1) * sizeof (CHAR16);\r
- Str.Str = ReallocatePool (Str.Str, NewSize, NewSize);\r
+ Str.Str = ReallocatePool (NewSize, NewSize, Str.Str);\r
ASSERT (Str.Str != NULL);\r
Str.Str[Str.Len] = 0;\r
return Str.Str;\r
\r
}\r
\r
-\r
-/**\r
- Adjusts the size of a previously allocated buffer.\r
-\r
-\r
- @param OldPool A pointer to the buffer whose size is being adjusted.\r
- @param OldSize The size of the current buffer.\r
- @param NewSize The size of the new buffer.\r
-\r
- @return The new buffer allocated.\r
-\r
-**/\r
-VOID *\r
-ReallocatePool (\r
- IN VOID *OldPool,\r
- IN UINTN OldSize,\r
- IN UINTN NewSize\r
- )\r
-{\r
- VOID *NewPool;\r
-\r
- NewPool = NULL;\r
- if (NewSize != 0) {\r
- NewPool = AllocateZeroPool (NewSize);\r
- }\r
-\r
- if (OldPool != NULL) {\r
- if (NewPool != NULL) {\r
- CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);\r
- }\r
-\r
- FreePool (OldPool);\r
- }\r
-\r
- return NewPool;\r
-}\r
-\r
-\r
/**\r
Append a string to a multi-string format.\r
\r
if (MultiStringSize + AppendStringSize > MAX_STRING_LENGTH ||\r
MultiStringSize > MAX_STRING_LENGTH) {\r
*MultiString = (EFI_STRING) ReallocatePool (\r
- (VOID *) (*MultiString),\r
MultiStringSize,\r
- MultiStringSize + AppendStringSize\r
+ MultiStringSize + AppendStringSize,\r
+ (VOID *) (*MultiString)\r
);\r
}\r
\r