ntruchsess / arduino_uip

UIPEthernet: A plugin-replacement of the stock Arduino Ethernet library for ENC28J60 shields and breakout boards. Full support for persistent (streaming) TCP-connections and UDP (Client and Server each), ARP, ICMP, DHCP and DNS. Build around Adam Dunkels uIP Stack. Further developed version can be found on https://github.com/UIPEthernet/UIPEthernet
489 stars 212 forks source link

dereferencing type-punned pointer will break strict-aliasing rules #166

Open twanek opened 8 years ago

twanek commented 8 years ago

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: http://stackoverflow.com/questions/4163126/dereferencing-type-punned-pointer-will-break-strict-aliasing-rules-warning

and this: http://stackoverflow.com/questions/7630150/dereferencing-type-punned-pointer-will-break-strict-aliasing-rules

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!