diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 8a84368b6..9bb574fe9 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -52,7 +52,7 @@ extern "C" { * * @note This number versions both OpenThread platform and user APIs. */ -#define OPENTHREAD_API_VERSION (526) +#define OPENTHREAD_API_VERSION (527) /** * @addtogroup api-instance diff --git a/include/openthread/platform/toolchain.h b/include/openthread/platform/toolchain.h index 2b92ec347..0084f9f92 100644 --- a/include/openthread/platform/toolchain.h +++ b/include/openthread/platform/toolchain.h @@ -293,6 +293,23 @@ extern "C" { } while (false) /* fallthrough */ #endif +// A known false positive warning occurs on some GCC toolchains, +// resulting in "error: writing x byte into a region of size 0". The following +// macros are used to suppress this warning/error in specific code blocks. + +#if defined(__GNUC__) && (__GNUC__ >= 7) + +#define OT_SUPPRESS_GCC_STRING_OP_BEGIN \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic warning \"-Wstringop-overflow=0\"") +#define OT_SUPPRESS_GCC_STRING_OP_END _Pragma("GCC diagnostic pop") + +#else + +#define OT_SUPPRESS_GCC_STRING_OP_BEGIN +#define OT_SUPPRESS_GCC_STRING_OP_END + +#endif + /** * @} */ diff --git a/src/core/thread/network_data_leader_ftd.cpp b/src/core/thread/network_data_leader_ftd.cpp index 6d69e6276..8a6cfa869 100644 --- a/src/core/thread/network_data_leader_ftd.cpp +++ b/src/core/thread/network_data_leader_ftd.cpp @@ -835,6 +835,15 @@ exit: return error; } +// The `AddHasRoute()`, `AddBorderRouter()`, and `AddServer()` methods +// below shift and update the network data bytes, which may involve +// inserting or updating a sub-TLV within an existing TLV. This can +// trigger a known false positive warning on some GCC toolchains. The +// `OT_SUPPRESS_GCC_STRING_OP_BEGIN`/ `OT_SUPPRESS_GCC_STRING_OP_END` +// macros are used to silence this check within these methods. + +OT_SUPPRESS_GCC_STRING_OP_BEGIN + Error Leader::AddHasRoute(const HasRouteTlv &aHasRoute, PrefixTlv &aDstPrefix, ChangedFlags &aChangedFlags) { Error error = kErrorNone; @@ -969,6 +978,8 @@ exit: return error; } +OT_SUPPRESS_GCC_STRING_OP_END + Error Leader::AllocateServiceId(uint8_t &aServiceId) const { Error error = kErrorNotFound;