diff mbox series

unit: pragma test_address to fix GCC warning on musl-libc

Message ID 20240730165138.274112-1-prestwoj@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series unit: pragma test_address to fix GCC warning on musl-libc | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-setupell success Prep - Setup ELL
prestwoj/iwd-ci-makedistcheck success Make Distcheck
prestwoj/iwd-ci-build success Build - Configure
prestwoj/iwd-ci-makecheckvalgrind success Make Check w/Valgrind
prestwoj/iwd-ci-makecheck success Make Check
prestwoj/iwd-ci-clang success clang PASS
prestwoj/iwd-ci-testrunner success test-runner PASS

Commit Message

James Prestwood July 30, 2024, 4:51 p.m. UTC
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(+)

Comments

Denis Kenzior July 30, 2024, 7:09 p.m. UTC | #1
Hi James,

On 7/30/24 11:51 AM, James Prestwood wrote:
> 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(+)
> 

Applied, thanks.

Regards,
-Denis
diff mbox series

Patch

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)
 {