[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [SUSPECTED SPAM][RESEND PATCH 1/2] tools/libxl: Mark pointer args of many functions constant
On 28/04/2021 18:12, Anthony PERARD wrote: > On Fri, Dec 18, 2020 at 01:37:44PM -0800, Elliott Mitchell wrote: >> --- a/tools/libs/light/libxl_internal.h >> +++ b/tools/libs/light/libxl_internal.h >> @@ -2073,9 +2073,9 @@ struct libxl__xen_console_reader { >> /* parse the string @s as a sequence of 6 colon separated bytes in to @mac >> */ >> _hidden int libxl__parse_mac(const char *s, libxl_mac mac); >> /* compare mac address @a and @b. 0 if the same, -ve if a<b and +ve if a>b >> */ >> -_hidden int libxl__compare_macs(libxl_mac *a, libxl_mac *b); >> +_hidden int libxl__compare_macs(const libxl_mac *a, const libxl_mac *b); >> /* return true if mac address is all zero (the default value) */ >> -_hidden int libxl__mac_is_default(libxl_mac *mac); >> +_hidden int libxl__mac_is_default(const libxl_mac *mac); > It turns out that older version of gcc complains about the const of > libxl_mac: > > > libxl_nic.c: In function 'libxl_mac_to_device_nic': > libxl_nic.c:40:9: error: passing argument 1 of 'libxl__compare_macs' from > incompatible pointer type [-Werror] > if (!libxl__compare_macs(&mac_n, &nics[i].mac)) { > ^ > In file included from libxl_nic.c:18:0: > libxl_internal.h:2076:13: note: expected 'const uint8_t (*)[6]' but > argument is of type 'uint8_t (*)[6]' > _hidden int libxl__compare_macs(const libxl_mac *a, const libxl_mac *b); > ^ > libxl_nic.c:40:9: error: passing argument 2 of 'libxl__compare_macs' from > incompatible pointer type [-Werror] > if (!libxl__compare_macs(&mac_n, &nics[i].mac)) { > ^ > In file included from libxl_nic.c:18:0: > libxl_internal.h:2076:13: note: expected 'const uint8_t (*)[6]' but > argument is of type 'uint8_t (*)[6]' > _hidden int libxl__compare_macs(const libxl_mac *a, const libxl_mac *b); > ^ > libxl_nic.c: In function 'libxl__device_nic_setdefault': > libxl_nic.c:69:5: error: passing argument 1 of 'libxl__mac_is_default' > from incompatible pointer type [-Werror] > if (libxl__mac_is_default(&nic->mac)) { > ^ > In file included from libxl_nic.c:18:0: > libxl_internal.h:2078:13: note: expected 'const uint8_t (*)[6]' but > argument is of type 'uint8_t (*)[6]' > _hidden int libxl__mac_is_default(const libxl_mac *mac); > ^ > cc1: all warnings being treated as errors That's because the typedef for libxl_mac violates one of the well known C beginner mistakes, by being a plain array behind the scenes. A prototype of 'const libxl_mac mac[]' might fair better, except it makes the code even more confusing to follow. ~Andrew
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |