From 109cbc1cda349f43bb93c6a5863c793cbf1929fe Mon Sep 17 00:00:00 2001 From: Jief L Date: Fri, 10 Apr 2020 16:27:04 +0300 Subject: [PATCH] Some more checked conversion to snprintf. --- rEFIt_UEFI/Platform/FixBiosDsdt.cpp | 6 +++--- rEFIt_UEFI/Platform/smbios.cpp | 5 ++--- rEFIt_UEFI/cpp_unit_test/printf_lite-test.cpp | 21 ++++++++++++++++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/rEFIt_UEFI/Platform/FixBiosDsdt.cpp b/rEFIt_UEFI/Platform/FixBiosDsdt.cpp index 3cb6c58bb..c880f9824 100755 --- a/rEFIt_UEFI/Platform/FixBiosDsdt.cpp +++ b/rEFIt_UEFI/Platform/FixBiosDsdt.cpp @@ -1068,7 +1068,7 @@ VOID findCPU(UINT8* dsdt, UINT32 length) if (!acpi_cpu_count) { for (i=0; i < acpi_cpu_max; i++) { acpi_cpu_name[i] = (__typeof_am__(acpi_cpu_name[i]))AllocateZeroPool(5); - AsciiSPrint(acpi_cpu_name[i], 5, "CPU%1x", i); + snprintf(acpi_cpu_name[i], 5, "CPU%X", i); acpi_cpu_processor_id[i] = (UINT8)(i & 0x7F); } } @@ -2438,7 +2438,7 @@ UINT32 FIXLPCB (UINT8 *dsdt, UINT32 len) pack = aml_add_package(met); aml_add_string(pack, "device-id"); aml_add_byte_buffer(pack, dataLPC, 4); - AsciiSPrint(NameCard, sizeof(NameCard), "pci8086,3a18"); + snprintf(NameCard, sizeof(NameCard), "pci8086,3a18"); aml_add_string(pack, "name"); aml_add_string_buffer(pack, &NameCard[0]); aml_add_string(pack, "compatible"); @@ -4092,7 +4092,7 @@ UINT32 FIXUSB (UINT8 *dsdt, UINT32 len) AsciiSPrint(UsbName[i], 5, "EHC%01x", EhciCount++); } } else { - AsciiSPrint(UsbName[i], 5, "USB%01d", i); + snprintf(UsbName[i], 5, "USB%d", i); // %01d is strictly the same as %d } DBG(" %s\n", UsbName[i]); ReplaceName(dsdt + adr1, Size, device_name[10], UsbName[i]); diff --git a/rEFIt_UEFI/Platform/smbios.cpp b/rEFIt_UEFI/Platform/smbios.cpp index d1ec237d2..43a55f7a2 100644 --- a/rEFIt_UEFI/Platform/smbios.cpp +++ b/rEFIt_UEFI/Platform/smbios.cpp @@ -914,7 +914,7 @@ VOID PatchTableType4() UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type4->AssetTag, BrandStr); //like mac // looks to be MicroCode revision if(gCPUStructure.MicroCode > 0){ - AsciiSPrint(BrandStr, 20, "%X", gCPUStructure.MicroCode); + snprintf(BrandStr, 20, "%X", gCPUStructure.MicroCode); UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type4->SerialNumber, BrandStr); } @@ -1351,7 +1351,7 @@ VOID PatchTableType17() snprintf(deviceLocator, 10, "DIMM%d", gRAMCount + 1); } else { snprintf(deviceLocator, 10, "DIMM%d", bank); - AsciiSPrint(bankLocator, 10, "BANK %llu", Index % channels); + snprintf(bankLocator, 10, "BANK %llu", Index % channels); UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type17->BankLocator, (CONST CHAR8*)&bankLocator[0]); } UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type17->DeviceLocator, (CONST CHAR8*)&deviceLocator[0]); @@ -1692,7 +1692,6 @@ VOID PatchTableType17() //now I want to update deviceLocator and bankLocator if (isMacPro) { snprintf(deviceLocator, 10, "DIMM%d", gRAMCount + 1); -// AsciiSPrint(bankLocator, 10, ""); bankLocator[0] = 0; } else { snprintf(deviceLocator, 10, "DIMM%d", bank); diff --git a/rEFIt_UEFI/cpp_unit_test/printf_lite-test.cpp b/rEFIt_UEFI/cpp_unit_test/printf_lite-test.cpp index 01897314a..d3f8346ed 100644 --- a/rEFIt_UEFI/cpp_unit_test/printf_lite-test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/printf_lite-test.cpp @@ -202,7 +202,10 @@ int printf_lite_tests(void) Test1arg(F("Āࠀ𐀀🧊Выход'utf16'из"), F("Āࠀ𐀀🧊Выход'%ls'из"), L"utf16"); Test1arg(F("Āࠀ𐀀🧊Выхо'ыход'из"), F("Āࠀ𐀀🧊Выхо'%s'из"), "ыход"); Test1arg(F("Āࠀ𐀀🧊Выхо'ыход'из"), F("Āࠀ𐀀🧊Выхо'%ls'из"), L"ыход"); - + + Test1arg(F("'u'"), F("'%s'"), (char*)L"utf16-string"); + + // Check %s with width specifier Test1arg(F("|a|"), F("|%4s|"), "a"); Test1arg(F("|aa|"), F("|%4s|"), "aa"); @@ -280,6 +283,11 @@ int printf_lite_tests(void) Test1arg(F("| 12|"), F("|%5d|"), 12); Test1arg(F("| 12|"), F("|%5u|"), 12); Test1arg(F("| c|"), F("|%5x|"), 12); + Test1arg(F("| C|"), F("|%5X|"), 12); + + // test pad char but no width (no effect) + Test1arg(F("|c|"), F("|%0x|"), 12); + Test1arg(F("|C|"), F("|%0X|"), 12); // test with specifier, 0 as pad char Test1arg(F("|00012|"), F("|%05d|"), 12); @@ -297,6 +305,17 @@ int printf_lite_tests(void) Test1arg(F("|12|"), F("|%02d|"), 12); Test1arg(F("|120|"), F("|%02d|"), 120); + + Test1arg(F("|0|"), F("|%01d|"), 0); + Test1arg(F("|1|"), F("|%01d|"), 1); + Test1arg(F("|100|"), F("|%01d|"), 100); + Test1arg(F("|10000|"), F("|%01d|"), 10000); + Test1arg(F("|-1|"), F("|%01d|"), -1); + Test1arg(F("|-100|"), F("|%01d|"), -100); + Test1arg(F("|-10000|"), F("|%01d|"), -10000); + + + // Test1arg float format Test1arg(F("|0.000000|"), F("|%0f|"), 0.0f); Test1arg(F("|0.000000|"), F("|%1f|"), 0.0f);