From b02127ec88a3edb6942b28b818cee6f4a73d1551 Mon Sep 17 00:00:00 2001 From: andrewfish Date: Thu, 26 Jan 2012 08:49:22 +0000 Subject: Fix bug where { NULL } did not terminate with a double NULL. Add support for passing in NULL for the string pack. Update the comments. signed-off-by: andrewfish git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12955 6f19259b-4bc3-4df7-8a09-765794883524 --- EmulatorPkg/CpuRuntimeDxe/Cpu.c | 47 ++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'EmulatorPkg') diff --git a/EmulatorPkg/CpuRuntimeDxe/Cpu.c b/EmulatorPkg/CpuRuntimeDxe/Cpu.c index 7be4146b4..fc8d325ff 100644 --- a/EmulatorPkg/CpuRuntimeDxe/Cpu.c +++ b/EmulatorPkg/CpuRuntimeDxe/Cpu.c @@ -137,12 +137,30 @@ CHAR8 *mCpuSmbiosType4Strings[] = { /** - Logs SMBIOS record. - - Note: This should be a genric library function. + Create SMBIOS record. + + Converts a fixed SMBIOS structure and an array of pointers to strings into + an SMBIOS record where the strings are cat'ed on the end of the fixed record + and terminated via a double NULL and add to SMBIOS table. + + SMBIOS_TABLE_TYPE32 gSmbiosType12 = { + { EFI_SMBIOS_TYPE_SYSTEM_CONFIGURATION_OPTIONS, sizeof (SMBIOS_TABLE_TYPE12), 0 }, + 1 // StringCount + }; + CHAR8 *gSmbiosType12Strings[] = { + "Not Found", + NULL + }; + + ... + LogSmbiosData ( + (EFI_SMBIOS_TABLE_HEADER*)&gSmbiosType12, + gSmbiosType12Strings + ); - @param Template Fixed SMBIOS structure - @param StringPack Array of strings to convert to an SMBIOS string pack. + @param Template Fixed SMBIOS structure, required. + @param StringArray Array of strings to convert to an SMBIOS string pack. + NULL is OK. **/ EFI_STATUS @@ -170,12 +188,21 @@ LogSmbiosData ( // Calculate the size of the fixed record and optional string pack Size = Template->Length; - for (Index = 0; StringPack[Index] != NULL; Index++) { - StringSize = AsciiStrSize (StringPack[Index]); - Size += StringSize; + if (StringPack == NULL) { + // At least a double null is required + Size += 2; + } else { + for (Index = 0; StringPack[Index] != NULL; Index++) { + StringSize = AsciiStrSize (StringPack[Index]); + Size += StringSize; + } + if (StringPack[0] == NULL) { + // At least a double null is required + Size += 1; + } + // Don't forget the terminating double null + Size += 1; } - // Don't forget the terminating double null - Size += 1; // Copy over Template Record = (EFI_SMBIOS_TABLE_HEADER *)AllocateZeroPool (Size); -- cgit v1.2.3