Page MenuHomeFreeBSD

Fix constant conversion warning in igmp
ClosedPublic

Authored by dim on Sep 3 2016, 11:13 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jun 9, 7:07 AM
Unknown Object (File)
Sun, Jun 9, 3:44 AM
Unknown Object (File)
May 16 2024, 4:59 AM
Unknown Object (File)
May 16 2024, 4:59 AM
Unknown Object (File)
May 11 2024, 2:14 PM
Unknown Object (File)
May 11 2024, 7:08 AM
Unknown Object (File)
Dec 20 2023, 1:44 AM
Unknown Object (File)
Dec 8 2023, 11:12 PM
Subscribers

Details

Summary

With clang 3.9.0, compiling sys/netinet/igmp.c results in the following
warning:

sys/netinet/igmp.c:546:21: error: implicit conversion from 'int' to 'char' changes value from 148 to -108 [-Werror,-Wconstant-conversion]
        p->ipopt_list[0] = IPOPT_RA;    /* Router Alert Option */
                         ~ ^~~~~~~~
sys/netinet/ip.h:153:19: note: expanded from macro 'IPOPT_RA'
#define IPOPT_RA                148             /* router alert */
                                ^~~

This is because ipopt_list is an array of char, so IPOPT_RA is wrapped
to a negative value. It would be nice to change ipopt_list to an array
of u_char, but it looks like that changes the ABI. So I added an
explicit cast to suppress the warning. The bits that end up in
ipopt_list[0] will be 0x94, as expected.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dim retitled this revision from to Fix constant conversion warning in igmp.
dim updated this object.
dim edited the test plan for this revision. (Show Details)
dim added reviewers: bms, glebius, emaste.
imp added a reviewer: imp.

I wonder how changing this from char to uint8_t would be an ABI change though...

This revision is now accepted and ready to land.Sep 4 2016, 3:45 AM
In D7777#161380, @imp wrote:

I wonder how changing this from char to uint8_t would be an ABI change though...

Because ipopt_list is in struct ipoption, which is a globally exported struct in sys/netinet/ip_var.h:

struct ipoption {
        struct  in_addr ipopt_dst;      /* first-hop dst if source routed */
        char    ipopt_list[MAX_IPOPTLEN];       /* options proper */
};

I'd be happy to change it to uint8_t or u_char, which doesn't change the size, but maybe some external applications depending on this signature might break?

This revision was automatically updated to reflect the committed changes.