]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: avoid warning about unaligned pointers
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 13 Apr 2019 09:47:47 +0000 (11:47 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 13 Apr 2019 09:55:04 +0000 (11:55 +0200)
With gcc-9.0.1-0.10.fc30.x86_64:
../src/network/netdev/macsec.c: In function ‘config_parse_macsec_port’:
../src/network/netdev/macsec.c:584:24: warning: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Waddress-of-packed-member]
  584 |                 dest = &c->sci.port;
      |                        ^~~~~~~~~~~~
../src/network/netdev/macsec.c:592:24: warning: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Waddress-of-packed-member]
  592 |                 dest = &b->sci.port;
      |                        ^~~~~~~~~~~~

(The alignment was probably OK, but it's nicer to avoid the warning anyway.)

src/network/netdev/macsec.c

index 15b5378f3068fd8d01725473597aa4944bf2d52a..ccc37cded4684494603a2b8587e698558e1ed1fc 100644 (file)
@@ -563,7 +563,7 @@ int config_parse_macsec_port(
         _cleanup_(macsec_receive_channel_free_or_set_invalidp) ReceiveChannel *c = NULL;
         MACsec *s = userdata;
         uint16_t port;
-        be16_t *dest;
+        void *dest;
         int r;
 
         assert(filename);
@@ -600,7 +600,7 @@ int config_parse_macsec_port(
                 return 0;
         }
 
-        *dest = htobe16(port);
+        unaligned_write_be16(dest, port);
 
         TAKE_PTR(b);
         TAKE_PTR(c);