Some side tracking fixing undefined behaviour and memory vulnurabilities

This commit is contained in:
2023-12-03 13:20:30 +01:00
parent 13a308ffa5
commit ca4cdc3fd9
8 changed files with 71 additions and 44 deletions

View File

@@ -90,7 +90,7 @@ int PtouchPrint::run() {
"Found more than one device of the same printer on bus. Currently not supported");
return -1;
}
printer->attachUsbDevice(devices[0]);
printer->attachUsbDevice(std::move(devices[0]));
auto status = printer->getPrinterStatus();
spdlog::info("Detected tape width is {}mm", status.tapeWidthMm);
auto bm = ptprnt::graphics::Bitmap<ptprnt::graphics::ALPHA8>(512, 128);
@@ -116,10 +116,10 @@ int PtouchPrint::run() {
unsigned int PtouchPrint::getCompatiblePrinters() {
auto usbDevs = mUsbDeviceFactory.findAllDevices();
for (auto usbDev : usbDevs) {
for (auto& usbDev : usbDevs) {
auto foundPrinterIt =
std::find_if(mCompatiblePrinters.begin(), mCompatiblePrinters.end(),
[usbDev](const std::shared_ptr<ptprnt::IPrinterDriver>& printer) {
[&usbDev](const std::shared_ptr<ptprnt::IPrinterDriver>& printer) {
return printer->getPid() == usbDev->getPid() &&
printer->getVid() == usbDev->getVid();
});