[Bugfix] Explicit getValue template returning nil value with convertable types.

This commit is contained in:
h2zero
2025-04-23 12:59:25 -06:00
committed by Ryan Powell
parent 54ec3f4c92
commit e18d78678f

View File

@ -305,9 +305,6 @@ class NimBLEAttValue {
*/
template <typename T>
T getValue(time_t* timestamp = nullptr, bool skipSizeCheck = false) const {
if (!skipSizeCheck && size() < sizeof(T)) {
return T();
}
if (timestamp != nullptr) {
# if CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
*timestamp = m_timestamp;
@ -316,7 +313,14 @@ class NimBLEAttValue {
# endif
}
return *(reinterpret_cast<const T*>(m_attr_value));
if (std::is_convertible<NimBLEAttValue, T>::value) {
return *this;
} else {
if (!skipSizeCheck && size() < sizeof(T)) {
return T();
}
return *(reinterpret_cast<const T*>(m_attr_value));
}
}
/*********************** Operators ************************/