From 8017fba1711dc572875463264ebc37a46d66c2b6 Mon Sep 17 00:00:00 2001 From: unlogisch04 <98281608+unlogisch04@users.noreply.github.com> Date: Fri, 23 May 2025 03:17:26 +0200 Subject: [PATCH] Fix build and runtime crash (#451) - Fix pointer issue - Fix null reference to string issue (int 255) - Recreate hex output for IMU address --- src/sensorinterface/i2cimpl.h | 4 +++- src/sensors/SensorBuilder.h | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sensorinterface/i2cimpl.h b/src/sensorinterface/i2cimpl.h index 14e258c..032c240 100644 --- a/src/sensorinterface/i2cimpl.h +++ b/src/sensorinterface/i2cimpl.h @@ -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: diff --git a/src/sensors/SensorBuilder.h b/src/sensors/SensorBuilder.h index e2730ab..5bed41d 100644 --- a/src/sensors/SensorBuilder.h +++ b/src/sensors/SensorBuilder.h @@ -269,7 +269,7 @@ public: } ); } else { - auto& regInterface = getRegisterInterface( + auto& regInterface = *getRegisterInterface( 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 );