linux-usb-gadgets / libusbgx

C library encapsulating the Linux kernel USB gadget configfs userspace API functionality
GNU General Public License v2.0
216 stars 72 forks source link

A compiling warning "-Waddress-of-packed-member" #57

Closed liuming50 closed 3 years ago

liuming50 commented 3 years ago

I encountered a comping warning as follows:

In file included from git/usbgadgethelper.c:11:
/usr/include/usbgx/usbg/function/net.h: In function 'usbg_f_net_get_dev_addr':
/usr/include/usbgx/usbg/function/net.h:131:19: warning: converting a packed 'struct ether_addr' pointer (alignment 1) to a 'union usbg_f_net_attr_val' pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
  131 |            (union usbg_f_net_attr_val *)addr);
      |                   ^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/netinet/if_ether.h:60,
                 from /usr/include/netinet/ether.h:25,
                 from /usr/include/usbgx/usbg/usbg.h:26,
                 from git/usbgadgethelper.c:9:
/usr/include/net/ethernet.h:33:8: note: defined here
   33 | struct ether_addr
      |        ^~~~~~~~~~
In file included from git/usbgadgethelper.c:11:
/usr/include/usbgx/usbg/function/net.h:43:7: note: defined here
   43 | union usbg_f_net_attr_val {
      |       ^~~~~~~~~~~~~~~~~~~
/usr/include/usbgx/usbg/function/net.h: In function 'usbg_f_net_get_host_addr':
/usr/include/usbgx/usbg/function/net.h:157:19: warning: converting a packed 'struct ether_addr' pointer (alignment 1) to a 'union usbg_f_net_attr_val' pointer (alignment 4) may result in an unaligned pointer value [-Waddress-of-packed-member]
  157 |            (union usbg_f_net_attr_val *)addr);
      |                   ^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/netinet/if_ether.h:60,
                 from /usr/include/netinet/ether.h:25,
                 from /usr/include/usbgx/usbg/usbg.h:26,
                 from git/usbgadgethelper.c:9:
/usr/include/net/ethernet.h:33:8: note: defined here
   33 | struct ether_addr
      |        ^~~~~~~~~~
In file included from git/usbgadgethelper.c:11:
/usr/include/usbgx/usbg/function/net.h:43:7: note: defined here
   43 | union usbg_f_net_attr_val {
      |       ^~~~~~~~~~~~~~~~~~~

when comping with gcc9/kernel 5.4, any idea how to fix this, it looks like a potential issue.

pabs3 commented 3 years ago

@liuming50 thanks for the bug report, fixed in git by copying the struct.

If you are interested in sharing more details, we would love to hear some more information about how/where you are using libusbgx.

  Which Linux distro are you using libusbgx on?   Are you compiling libusbgx yourself or using a distro package?   What kind of device are you using libusbgx on?   Which of the libusbgx functions are you using?   Are you using gadget-tool (gt) and or gadgetd?   Anything else you want to share?

-- bye, pabs

https://bonedaddy.net/pabs3/