uipethernet: dereferencing type-punned pointer will break strict-aliasing rules

hello!

if i enable verbose output + warnings in arduino ide 1.6.12, i’ve got a lot (maybe 50+) warnings like this, when compiling:

C:\ARDUINO\libraries\UIPEthernet\utility\uip.h:884:32: note: in definition of macro 'uip_ipaddr_copy'

((u16_t *)dest)[1] = ((u16_t *)src)[1]; \

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:1264:19: note: in expansion of macro 'BUF'

uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:226:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.h:884:32: note: in definition of macro 'uip_ipaddr_copy'

((u16_t *)dest)[1] = ((u16_t *)src)[1]; \

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:1264:19: note: in expansion of macro 'BUF'

uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:226:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:1308:22: note: in expansion of macro 'BUF'

uip_connr->lport = BUF->destport;

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:226:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:1309:22: note: in expansion of macro 'BUF'

uip_connr->rport = BUF->srcport;

^

In file included from C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:82:0:

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:226:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.h:883:53: note: in definition of macro 'uip_ipaddr_copy'

((u16_t *)dest)[0] = ((u16_t *)src)[0]; \

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:1310:39: note: in expansion of macro 'BUF'

uip_ipaddr_copy(uip_connr->ripaddr, BUF->srcipaddr);

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:226:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.h:883:53: note: in definition of macro 'uip_ipaddr_copy'

((u16_t *)dest)[0] = ((u16_t *)src)[0]; \

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:1310:39: note: in expansion of macro 'BUF'

uip_ipaddr_copy(uip_connr->ripaddr, BUF->srcipaddr);

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:226:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.h:884:53: note: in definition of macro 'uip_ipaddr_copy'

((u16_t *)dest)[1] = ((u16_t *)src)[1]; \

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:1310:39: note: in expansion of macro 'BUF'

uip_ipaddr_copy(uip_connr->ripaddr, BUF->srcipaddr);

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:226:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.h:884:53: note: in definition of macro 'uip_ipaddr_copy'

((u16_t *)dest)[1] = ((u16_t *)src)[1]; \

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:1310:39: note: in expansion of macro 'BUF'

uip_ipaddr_copy(uip_connr->ripaddr, BUF->srcipaddr);

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:226:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:1320:27: note: in expansion of macro 'BUF'

uip_connr->rcv_nxt[3] = BUF->seqno[3];

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:226:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:1321:27: note: in expansion of macro 'BUF'

uip_connr->rcv_nxt[2] = BUF->seqno[2];

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:226:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:1322:27: note: in expansion of macro 'BUF'

uip_connr->rcv_nxt[1] = BUF->seqno[1];

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:226:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

^

C:\ARDUINO\libraries\UIPEthernet\utility\uip.c:1323:27: note: in expansion of macro 'BUF'

uip_connr->rcv_nxt[0] = BUF->seqno[0];

(this is only a small part of the list)

however, i’m not on the programming level to understand these warnings, but googling around i’ve found this:

and this:

they say it could cause problems:
“The strict aliasing rule makes this setup illegal, two unrelated types can’t point to the same memory. Only char* has this privilege. Unfortunately you can still code this way, maybe get some warnings, but have it compile fine.”

“According to the C and C++ standards, it is undefined behaviour to access a variable of a given type through a pointer to another type.”

can someone explain if this can cause problems, or should i ignore it? currently i have random freezes with my setup, this is why i bother…

thank you!

Hi!

The "warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]" maybe cause error on big-endian systems.

The "in expansion of macro" is only NOTE.

This messages don't cause random freezes. (In my opinion.)

The less free memory cause random freezes usually.

I work on UIPEthernet at this time. You can download my updated version from: https://github.com/UIPEthernet/UIPEthernet

I try remove all warnings at compiling.

Best regards.