mirror of
https://github.com/espressif/openthread.git
synced 2026-07-27 14:27:47 +00:00
[toolchain] suppress gcc string operation warning (#11810)
Introduces macros to suppress a known false-positive GCC warning "-Wstringop-overflow=0" which can be triggered when manipulating network data. The `AddHasRoute()`, `AddBorderRouter()`, and `AddServer()` methods shift and update the network data bytes, which may involve inserting or updating a sub-TLV within an existing TLV. This can trigger a "writing x byte into a region of size 0" error on some GCC toolchains. This change adds the `OT_SUPPRESS_GCC_STRING_OP_BEGIN` and `OT_SUPPRESS_GCC_STRING_OP_END` macros to silence this specific warning within these code blocks.
This commit is contained in:
committed by
Jonathan Hui
parent
3c8049ad65
commit
8b1f217ef6
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user