https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90186

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note that using #pragma pack(1) on struct Ipv4 makes u_short members not
naturally aligned and thus code like

        void UpdateChecksum()
        {   
            u_long sum(0);

            SetChecksum(0);

            u_short *buf = (u_short*)ip->Payload();
            u_long nwords = ip->PayloadSize() / 2;

            for (unsigned i = 0; i < nwords; ++i)
            {   

                sum += ntohs(*buf++);

dereferences pointers to u_short that might not be aligned to a 2 byte
boundary.

Confirmed though, even when using -fno-inline.  -fno-strict-aliasing fixes
it.  Possibly the very same issue above - using u_short * to access memory
with a different dynamic type.  The same happens here:

            buf = (u_short*)&ph;
            nwords = 6;

            for (unsigned i = 0; i < nwords; ++i)
            {

                sum += ntohs(*buf++);

ph is of type PseudoHeader.  You cannot use lvalues of type u_short to
refer to them.

Reply via email to