Some side tracking fixing undefined behaviour and memory vulnurabilities
All checks were successful
Build ptprnt / build (push) Successful in 3m23s
All checks were successful
Build ptprnt / build (push) Successful in 3m23s
This commit is contained in:
@@ -19,9 +19,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "libusb.h"
|
||||
#include "libusbwrap/UsbDevice.hpp"
|
||||
#include "libusbwrap/interface/IUsbDeviceFactory.hpp"
|
||||
|
||||
namespace libusbwrap {
|
||||
|
||||
constexpr const uint16_t LIBUSB_BITMASK_ALL = 0xffff;
|
||||
|
||||
class UsbDeviceFactory : public IUsbDeviceFactory {
|
||||
public:
|
||||
UsbDeviceFactory() = default;
|
||||
@@ -39,7 +46,7 @@ class UsbDeviceFactory : public IUsbDeviceFactory {
|
||||
*
|
||||
* @return std::vector<std::shared_ptr<IUsbDevice>> Vector of all detected USB devices
|
||||
*/
|
||||
std::vector<std::shared_ptr<IUsbDevice>> findAllDevices() override;
|
||||
std::vector<std::unique_ptr<IUsbDevice>> findAllDevices() override;
|
||||
/**
|
||||
* @brief Gets all devices with certain vid/pid combination.
|
||||
* If only one device of certain type is connected, vector is usually only one element
|
||||
@@ -48,17 +55,17 @@ class UsbDeviceFactory : public IUsbDeviceFactory {
|
||||
* @param pid ProductId of the devices to find
|
||||
* @return std::vector<std::shared_ptr<IUsbDevice>> Vector of detected USB devices based on vid/pid
|
||||
*/
|
||||
std::vector<std::shared_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) override;
|
||||
std::vector<std::unique_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) override;
|
||||
|
||||
private:
|
||||
// methods
|
||||
int refreshDeviceList();
|
||||
std::vector<std::shared_ptr<IUsbDevice>> buildMaskedDeviceVector(uint16_t vidMask,
|
||||
ssize_t refreshDeviceList();
|
||||
std::vector<std::unique_ptr<IUsbDevice>> buildMaskedDeviceVector(uint16_t vidMask,
|
||||
uint16_t pidMask, uint16_t vid,
|
||||
uint16_t pid);
|
||||
// members
|
||||
libusb_context* mLibusbCtx{nullptr};
|
||||
libusb_device** mLibusbDeviceList{};
|
||||
std::vector<usbDevice_ptr> mLibusbDeviceList{};
|
||||
bool mDeviceListInitialized = false;
|
||||
};
|
||||
} // namespace libusbwrap
|
||||
Reference in New Issue
Block a user