Fix build and runtime crash (#451)

- Fix pointer issue
- Fix null reference to string issue (int 255)
- Recreate hex output for IMU address
This commit is contained in:
unlogisch04
2025-05-23 03:17:26 +02:00
committed by GitHub
parent 6ee3aab87e
commit 8017fba171
2 changed files with 5 additions and 3 deletions

View File

@@ -82,7 +82,9 @@ struct I2CImpl : public RegisterInterface {
uint8_t getAddress() const override { return m_devAddr; }
std::string toString() const {
return std::string("I2C(") + std::to_string(m_devAddr) + std::string(")");
char buf[16];
std::snprintf(buf, sizeof(buf), "I2C(0x%02x)", m_devAddr);
return std::string(buf);
}
private:

View File

@@ -269,7 +269,7 @@ public:
}
);
} else {
auto& regInterface = getRegisterInterface<SensorType>(
auto& regInterface = *getRegisterInterface<SensorType>(
sensorID,
sensorInterface,
accessInterface
@@ -303,7 +303,7 @@ public:
sensorDef.imuInterface.toString().c_str(),
sensorDef.rotation,
sensorDef.sensorInterface->toString().c_str(),
sensorDef.intPin->toString().c_str(),
sensorDef.intPin ? sensorDef.intPin->toString().c_str() : "None",
sensorDef.extraParam,
sensorDef.optional
);