/* Append an active boot option to BootOrder, reallocating the latter if needed. */
STATIC RETURN_STATUS BootOrderAppend(IN OUT BOOT_ORDER *BootOrder, IN OUT ACTIVE_OPTION *ActiveOption)
/* Append an active boot option to BootOrder, reallocating the latter if needed. */
STATIC RETURN_STATUS BootOrderAppend(IN OUT BOOT_ORDER *BootOrder, IN OUT ACTIVE_OPTION *ActiveOption)
{
  if (BootOrder->Produced == BootOrder->Allocated) {
    UINTN   AllocatedNew;
    UINT16  *DataNew;
    ASSERT (BootOrder->Allocated > 0);
    AllocatedNew = BootOrder->Allocated * 2;
    DataNew      = ReallocatePool (
                     BootOrder->Allocated * sizeof (*BootOrder->Data),
                     AllocatedNew         * sizeof (*DataNew),
                     BootOrder->Data
                     );
    if (DataNew == NULL) {
      return RETURN_OUT_OF_RESOURCES;
    }
    BootOrder->Allocated = AllocatedNew;
    BootOrder->Data      = DataNew;
  }
  BootOrder->Data[BootOrder->Produced++] =
    (UINT16)ActiveOption->BootOption->OptionNumber;
  ActiveOption->Appended = TRUE;
  return RETURN_SUCCESS;
}