[PATCH] unit: pragma test_address to fix GCC warning on musl-libc
James Prestwood <[email protected]> Tue, 30 Jul 2024 09:51:38 -0700
| Newsgroups | dev.linux.lists.ell |
|---|---|
| Message-ID | <[email protected]> |
This appears to be a compiler bug causing an array-bounds warning:
unit/test-rtnl.c: In function 'test_address':
unit/test-rtnl.c:285:13: error: offset '2305843009213693948' outside bounds of constant string [-Werror=array-bounds]
285 | static void test_address(const void *data)
| ^~~~~~~~~~~~
unit/test-rtnl.c:215:36: note: 'address' declared here
215 | static const struct l_rtnl_address address = {
| ^~~~~~~
There is nothing visually wrong with the code, and it appears to be
having an issue with the "label" member, which is a simple constant
string. Doing things like adding a member before "label" or making
"address" not const seems to make it go away, making it really
appear as if the compiler is confused.
Fix this by adding a pragma for that test function.
---
unit/test-rtnl.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/unit/test-rtnl.c b/unit/test-rtnl.c
index 25e1859..59d8492 100644
--- a/unit/test-rtnl.c
+++ b/unit/test-rtnl.c
@@ -279,6 +279,8 @@ static struct ifaddrmsg *build_ifaddrmsg(const struct l_rtnl_address *addr,
return ifamsg;
}
+_Pragma("GCC diagnostic push")
+_Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
static void test_address(const void *data)
{
static const int ifindex = 3;
@@ -293,6 +295,7 @@ static void test_address(const void *data)
assert(messages_equal(nlm, ifamsg, ifamsg_len));
l_netlink_message_unref(nlm);
}
+_Pragma("GCC diagnostic pop")
static void signal_handler(uint32_t signo, void *user_data)
{
--
2.34.1