From e18d78678f89f8dfb6f1d5b21fdfce89c799b1ca Mon Sep 17 00:00:00 2001 From: h2zero Date: Wed, 23 Apr 2025 12:59:25 -0600 Subject: [PATCH] [Bugfix] Explicit getValue template returning nil value with convertable types. --- src/NimBLEAttValue.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/NimBLEAttValue.h b/src/NimBLEAttValue.h index 3354fc5..67a2cea 100644 --- a/src/NimBLEAttValue.h +++ b/src/NimBLEAttValue.h @@ -305,9 +305,6 @@ class NimBLEAttValue { */ template 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(m_attr_value)); + if (std::is_convertible::value) { + return *this; + } else { + if (!skipSizeCheck && size() < sizeof(T)) { + return T(); + } + return *(reinterpret_cast(m_attr_value)); + } } /*********************** Operators ************************/