Skip to content

Commit ff9004d

Browse files
committed
[Bugfix] Explicit getValue template returning nil value with convertable types.
1 parent 2b2a56c commit ff9004d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/NimBLEAttValue.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,6 @@ class NimBLEAttValue {
305305
*/
306306
template <typename T>
307307
T getValue(time_t* timestamp = nullptr, bool skipSizeCheck = false) const {
308-
if (!skipSizeCheck && size() < sizeof(T)) {
309-
return T();
310-
}
311308
if (timestamp != nullptr) {
312309
# if CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
313310
*timestamp = m_timestamp;
@@ -316,7 +313,14 @@ class NimBLEAttValue {
316313
# endif
317314
}
318315

319-
return *(reinterpret_cast<const T*>(m_attr_value));
316+
if (std::is_convertible<NimBLEAttValue, T>::value) {
317+
return *this;
318+
} else {
319+
if (!skipSizeCheck && size() < sizeof(T)) {
320+
return T();
321+
}
322+
return *(reinterpret_cast<const T*>(m_attr_value));
323+
}
320324
}
321325

322326
/*********************** Operators ************************/

0 commit comments

Comments
 (0)