diff --git a/rEFIt_UEFI/Platform/FixBiosDsdt.cpp b/rEFIt_UEFI/Platform/FixBiosDsdt.cpp index c880f9824..2be789d3f 100755 --- a/rEFIt_UEFI/Platform/FixBiosDsdt.cpp +++ b/rEFIt_UEFI/Platform/FixBiosDsdt.cpp @@ -2961,7 +2961,7 @@ UINT32 FIXNetwork (UINT8 *dsdt, UINT32 len, UINT32 card) if (gSettings.FakeLAN) { FakeID = gSettings.FakeLAN >> 16; FakeVen = gSettings.FakeLAN & 0xFFFF; - AsciiSPrint(NameCard, 32, "pci%04x,%04x", FakeVen, FakeID); + snprintf(NameCard, 32, "pci%04X,%04X", FakeVen, FakeID); LowCase(NameCard); Netmodel[card] = get_net_model((FakeVen << 16) + FakeID); } @@ -3164,7 +3164,7 @@ UINT32 FIXAirport (UINT8 *dsdt, UINT32 len) if (gSettings.FakeWIFI) { FakeID = gSettings.FakeWIFI >> 16; FakeVen = gSettings.FakeWIFI & 0xFFFF; - AsciiSPrint(NameCard, 32, "pci%04x,%04x", FakeVen, FakeID); + snprintf(NameCard, 32, "pci%04x,%04x", FakeVen, FakeID); LowCase(NameCard); } @@ -4052,8 +4052,8 @@ UINT32 FIXUSB (UINT8 *dsdt, UINT32 len) if (usb > 0) { for (i = 0; i < usb; i++) { - INTN XhciCount = 1; - INTN EhciCount = 0; + INT32 XhciCount = 1; + INT32 EhciCount = 0; // find USB adr for (j = 0x20; len >= 4 && j < len - 4; j++) { if (CmpAdr(dsdt, j, USBADR[i])) { //j+4 -> _ADR @@ -4081,15 +4081,15 @@ UINT32 FIXUSB (UINT8 *dsdt, UINT32 len) USBADR[i], USBADR2[i], k, device_name[10]); if (USB30[i]) { if (gSettings.NameXH00) { - AsciiSPrint(UsbName[i], 5, "XH%02x", XhciCount++); + snprintf(UsbName[i], 5, "XH%02x", XhciCount++); } else { - AsciiSPrint(UsbName[i], 5, "XHC%01x", XhciCount++); + snprintf(UsbName[i], 5, "XHC%01x", XhciCount++); } } else if (USB20[i]) { if (gSettings.NameEH00) { - AsciiSPrint(UsbName[i], 5, "EH%02x", EhciCount++); + snprintf(UsbName[i], 5, "EH%02x", EhciCount++); } else { - AsciiSPrint(UsbName[i], 5, "EHC%01x", EhciCount++); + snprintf(UsbName[i], 5, "EHC%01x", EhciCount++); } } else { snprintf(UsbName[i], 5, "USB%d", i); // %01d is strictly the same as %d diff --git a/rEFIt_UEFI/Platform/Settings.cpp b/rEFIt_UEFI/Platform/Settings.cpp index cdd78c463..7ab2f4e63 100644 --- a/rEFIt_UEFI/Platform/Settings.cpp +++ b/rEFIt_UEFI/Platform/Settings.cpp @@ -4852,7 +4852,7 @@ GetUserSettings( } Dict2 = GetProperty (Prop2, "PciAddr"); if (Dict2 != NULL) { - INTN Bus, Dev, Func; + UINT8 Bus, Dev, Func; CHAR8 *Str = Dict2->string; if (Str[2] != ':') { @@ -4864,7 +4864,7 @@ GetUserSettings( Dev = hexstrtouint8(&Str[3]); Func = hexstrtouint8(&Str[6]); DeviceAddr = PCIADDR(Bus, Dev, Func); - AsciiSPrint(Label, 64, "[%02x:%02x.%02x] ", Bus, Dev, Func); + snprintf(Label, 64, "[%02X:%02X.%02X] ", Bus, Dev, Func); DBG(" %s", Label); } else { DBG (" no PciAddr\n"); @@ -6861,7 +6861,7 @@ GetDevices () default: gfx->Vendor = Unknown; - AsciiSPrint (gfx->Model, 64, "pci%04x,%04x", Pci.Hdr.VendorId, Pci.Hdr.DeviceId); + snprintf (gfx->Model, 64, "pci%04X,%04X", Pci.Hdr.VendorId, Pci.Hdr.DeviceId); LowCase(gfx->Model); gfx->Ports = 1; gfx->Connectors = (1 << NGFX); diff --git a/rEFIt_UEFI/Platform/ati.cpp b/rEFIt_UEFI/Platform/ati.cpp index 44619fb8c..d416b421c 100644 --- a/rEFIt_UEFI/Platform/ati.cpp +++ b/rEFIt_UEFI/Platform/ati.cpp @@ -1322,7 +1322,7 @@ BOOLEAN get_name_pci_val(value_t *val, INTN index, BOOLEAN Sier) return FALSE; } - AsciiSPrint(pciName, 15, "pci1002,%04x", gSettings.FakeATI >> 16); + snprintf(pciName, 15, "pci1002,%04X", gSettings.FakeATI >> 16); LowCase(pciName); val->type = kStr; val->size = 13; @@ -2113,7 +2113,7 @@ BOOLEAN setup_ati_devprop(LOADER_ENTRY *Entry, pci_dt_t *ati_dev) FakeID = gSettings.FakeATI >> 16; devprop_add_value(card->device, "device-id", (UINT8*)&FakeID, 4); devprop_add_value(card->device, "ATY,DeviceID", (UINT8*)&FakeID, 2); - AsciiSPrint(compatible, 64, "pci1002,%04x", FakeID); + snprintf(compatible, 64, "pci1002,%04x", FakeID); LowCase(compatible); devprop_add_value(card->device, "@0,compatible", (UINT8*)&compatible[0], 12); FakeID = gSettings.FakeATI & 0xFFFF; diff --git a/rEFIt_UEFI/Platform/device_inject.cpp b/rEFIt_UEFI/Platform/device_inject.cpp index cc368ab7d..da1395ee6 100644 --- a/rEFIt_UEFI/Platform/device_inject.cpp +++ b/rEFIt_UEFI/Platform/device_inject.cpp @@ -285,17 +285,17 @@ CHAR8 *devprop_generate_string(DevPropString *StringBuf) if(!buffer) return NULL; - AsciiSPrint(buffer, len, "%08X%08X%04X%04X", SwapBytes32(StringBuf->length), StringBuf->WHAT2, + snprintf(buffer, len, "%08X%08X%04X%04X", SwapBytes32(StringBuf->length), StringBuf->WHAT2, SwapBytes16(StringBuf->numentries), StringBuf->WHAT3); buffer += 24; while(i < StringBuf->numentries) { UINT8 *dataptr = StringBuf->entries[i]->data; - AsciiSPrint(buffer, len, "%08X%04X%04X", SwapBytes32(StringBuf->entries[i]->length), + snprintf(buffer, len, "%08X%04X%04X", SwapBytes32(StringBuf->entries[i]->length), SwapBytes16(StringBuf->entries[i]->numentries), StringBuf->entries[i]->WHAT2); //FIXME: wrong buffer sizes! buffer += 16; - AsciiSPrint(buffer, len, "%02X%02X%04X%08X%08X", StringBuf->entries[i]->acpi_dev_path.type, + snprintf(buffer, len, "%02X%02X%04X%08X%08X", StringBuf->entries[i]->acpi_dev_path.type, StringBuf->entries[i]->acpi_dev_path.subtype, SwapBytes16(StringBuf->entries[i]->acpi_dev_path.length), SwapBytes32(StringBuf->entries[i]->acpi_dev_path._HID), @@ -303,7 +303,7 @@ CHAR8 *devprop_generate_string(DevPropString *StringBuf) buffer += 24; for(x = 0; x < StringBuf->entries[i]->num_pci_devpaths; x++) { - AsciiSPrint(buffer, len, "%02X%02X%04X%02X%02X", StringBuf->entries[i]->pci_dev_path[x].type, + snprintf(buffer, len, "%02X%02X%04X%02X%02X", StringBuf->entries[i]->pci_dev_path[x].type, StringBuf->entries[i]->pci_dev_path[x].subtype, SwapBytes16(StringBuf->entries[i]->pci_dev_path[x].length), StringBuf->entries[i]->pci_dev_path[x].function, @@ -311,13 +311,13 @@ CHAR8 *devprop_generate_string(DevPropString *StringBuf) buffer += 12; } - AsciiSPrint(buffer, len, "%02X%02X%04X", StringBuf->entries[i]->path_end.type, + snprintf(buffer, len, "%02X%02X%04X", StringBuf->entries[i]->path_end.type, StringBuf->entries[i]->path_end.subtype, SwapBytes16(StringBuf->entries[i]->path_end.length)); buffer += 8; for(x = 0; x < (StringBuf->entries[i]->length) - (24 + (6 * StringBuf->entries[i]->num_pci_devpaths)); x++) { - AsciiSPrint(buffer, len, "%02X", *dataptr++); + snprintf(buffer, len, "%02X", *dataptr++); buffer += 2; } i++; @@ -408,7 +408,7 @@ BOOLEAN set_eth_props(pci_dt_t *eth_dev) if (gSettings.FakeLAN) { UINT32 FakeID = gSettings.FakeLAN >> 16; devprop_add_value(device, "device-id", (UINT8*)&FakeID, 4); - AsciiSPrint(compatible, 64, "pci%04x,%04x", (gSettings.FakeLAN & 0xFFFF), FakeID); + snprintf(compatible, 64, "pci%04X,%04X", (gSettings.FakeLAN & 0xFFFF), FakeID); LowCase(compatible); devprop_add_value(device, "compatible", (UINT8*)&compatible[0], 12); FakeID = gSettings.FakeLAN & 0xFFFF; diff --git a/rEFIt_UEFI/Platform/kext_inject.cpp b/rEFIt_UEFI/Platform/kext_inject.cpp index 4f746df8f..873f0a73a 100644 --- a/rEFIt_UEFI/Platform/kext_inject.cpp +++ b/rEFIt_UEFI/Platform/kext_inject.cpp @@ -843,7 +843,7 @@ EFI_STATUS InjectKexts(/*IN EFI_MEMORY_DESCRIPTOR *Desc*/ IN UINT32 deviceTreeP, mm = (_DeviceTreeBuffer*) (((UINT8*)prop) + sizeof(DeviceTreeNodeProperty)); mm->paddr = (UINT32)KextBase; mm->length = KextEntry->kext.length; - AsciiSPrint(prop->Name, 31, "Driver-%x", KextBase); + snprintf(prop->Name, 31, "Driver-%X", (UINT32)KextBase); drvPtr += sizeof(DeviceTreeNodeProperty) + sizeof(_DeviceTreeBuffer); KextBase = RoundPage(KextBase + KextEntry->kext.length); diff --git a/rEFIt_UEFI/Platform/spd.cpp b/rEFIt_UEFI/Platform/spd.cpp index aa9f3c1df..a7c8b0754 100644 --- a/rEFIt_UEFI/Platform/spd.cpp +++ b/rEFIt_UEFI/Platform/spd.cpp @@ -542,12 +542,12 @@ CHAR8* getDDRSerial(UINT8* spd) CHAR8* asciiSerial; //[16]; asciiSerial = (__typeof__(asciiSerial))AllocatePool(17); if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR4) { // DDR4 - AsciiSPrint(asciiSerial, 17, "%2X%2X%2X%2X%2X%2X%2X%2X", SMST(325) /*& 0x7*/, SLST(325), SMST(326), SLST(326), SMST(327), SLST(327), SMST(328), SLST(328)); + snprintf(asciiSerial, 17, "%02X%02X%02X%02X%02X%02X%02X%02X", SMST(325) /*& 0x7*/, SLST(325), SMST(326), SLST(326), SMST(327), SLST(327), SMST(328), SLST(328)); } else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) { // DDR3 - AsciiSPrint(asciiSerial, 17, "%2X%2X%2X%2X%2X%2X%2X%2X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125)); + snprintf(asciiSerial, 17, "%02X%02X%02X%02X%02X%02X%02X%02X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125)); } else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) { // DDR2 or DDR - AsciiSPrint(asciiSerial, 17, "%2X%2X%2X%2X%2X%2X%2X%2X", SMST(95) /*& 0x7*/, SLST(95), SMST(96), SLST(96), SMST(97), SLST(97), SMST(98), SLST(98)); + snprintf(asciiSerial, 17, "%02X%02X%02X%02X%02X%02X%02X%02X", SMST(95) /*& 0x7*/, SLST(95), SMST(96), SLST(96), SMST(97), SLST(97), SMST(98), SLST(98)); } else { AsciiStrCpyS(asciiSerial, 17, "0000000000000000"); } diff --git a/rEFIt_UEFI/cpp_unit_test/printlib-test.cpp b/rEFIt_UEFI/cpp_unit_test/printlib-test.cpp index 46434cb7a..af68524e2 100644 --- a/rEFIt_UEFI/cpp_unit_test/printlib-test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/printlib-test.cpp @@ -228,6 +228,14 @@ int printlib_tests(void) Test1arg(F("|ABFE|"), F("|%x|"), 0xABFE); // %x for PrintLib is %X for printf Test1arg(F("|ABFED|"), F("|%x|"), 0xABFED); // %x for PrintLib is %X for printf Test1arg(F("|ABF|"), F("|%X|"), 0xABF); + Test1arg(F("|FFFFFFF6|"), F("|%x|"), -10); + Test1arg(F("|FFFFFFF6|"), F("|%X|"), -10); + Test1arg(F("|FFFFFFF6|"), F("|%2X|"), -10); + Test1arg(F("|FFFFFFF6|"), F("|%0X|"), -10); + Test1arg(F("| FFFFFFF6|"), F("|%20x|"), -10); + Test1arg(F("|FFFFFFF6|"), F("|%lx|"), -10); + Test1arg(F("|FFFFFFFFFFFFFFF6|"), F("|%lX|"), -10L); + Test1arg(F("|0000FFFFFFFFFFFFFFF6|"), F("|%20lX|"), -10L); // test with specifier, space as pad char Test1arg(F("| 0|"), F("|%5d|"), 0); @@ -262,7 +270,7 @@ int printlib_tests(void) Test1arg(F("|80123456|"), F("|%07X|"), 0xFFFFFFFF80123456); Test1arg(F("|080123456|"), F("|%09X|"), 0xFFFFFFFF80123456); Test1arg(F("|00000000000080123456|"), F("|%020X|"), 0xFFFFFFFF80123456); - Test1arg(F("|0000FFFFFFFF80123456|"), F("|%020X|"), 0xFFFFFFFF80123456); + Test1arg(F("|0000FFFFFFFF80123456|"), F("|%020lX|"), 0xFFFFFFFF80123456); // test limits int16_t i; diff --git a/rEFIt_UEFI/refit/menu.cpp b/rEFIt_UEFI/refit/menu.cpp index da5d93239..d69ecdc1f 100644 --- a/rEFIt_UEFI/refit/menu.cpp +++ b/rEFIt_UEFI/refit/menu.cpp @@ -248,7 +248,7 @@ VOID FillInputs(BOOLEAN New) InputItems[InputItemsCount++].BValue = gSettings.InjectNVidia; InputItems[InputItemsCount].ItemType = ASString; //22+6i for (j=0; j<8; j++) { - AsciiSPrint((CHAR8*)&tmp[2*j], 3, "%02x", gSettings.Dcfg[j]); + snprintf((CHAR8*)&tmp[2*j], 3, "%02X", gSettings.Dcfg[j]); } if (New) { InputItems[InputItemsCount].SValue = (__typeof__(InputItems[InputItemsCount].SValue))AllocateZeroPool(40); @@ -281,7 +281,7 @@ VOID FillInputs(BOOLEAN New) if (gGraphics[i].Vendor == Nvidia) { InputItems[InputItemsCount].ItemType = ASString; //24+6i for (j=0; j<20; j++) { - AsciiSPrint((CHAR8*)&tmp[2*j], 3, "%02X", gSettings.NVCAP[j]); + snprintf((CHAR8*)&tmp[2*j], 3, "%02X", gSettings.NVCAP[j]); } if (New) { InputItems[InputItemsCount].SValue = (__typeof__(InputItems[InputItemsCount].SValue))AllocateZeroPool(84);