Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Wconversion -Wsign-conversion -Werror compilation errors #57

Open
iu1j4 opened this issue Jan 23, 2021 · 0 comments
Open

-Wconversion -Wsign-conversion -Werror compilation errors #57

iu1j4 opened this issue Jan 23, 2021 · 0 comments

Comments

@iu1j4
Copy link

iu1j4 commented Jan 23, 2021

When I try to compile liboping from source with:
CFLAGS="-Wconversion -Wsign-conversion -Werror" ./configure --prefix=/usr --without-perl-bindings --libdir=/usr/lib --disable-static
I got a lot of compile errors:
liboping.c: In function 'ping_icmp4_checksum':
liboping.c:273:8: error: conversion from 'uint32_t' {aka 'unsigned int'} to 'uint16_t' {aka 'short unsigned int'} may change value [-Werror=conversion]
273 | ret = ~sum;
| ^
liboping.c: In function 'ping_receive_one':
liboping.c:594:50: error: conversion to 'size_t' {aka 'long unsigned int'} from 'ssize_t' {aka 'long int'} may change the sign of the result [-Werror=sign-conversion]
594 | host = ping_receive_ipv4 (obj, payload_buffer, payload_buffer_len);
| ^~~~~~~~~~~~~~~~~~
liboping.c:600:50: error: conversion to 'size_t' {aka 'long unsigned int'} from 'ssize_t' {aka 'long int'} may change the sign of the result [-Werror=sign-conversion]
600 | host = ping_receive_ipv6 (obj, payload_buffer, payload_buffer_len);
| ^~~~~~~~~~~~~~~~~~
liboping.c: In function 'ping_send_one_ipv4':
liboping.c:693:25: error: conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} may change value [-Werror=conversion]
693 | .icmp_id = htons (ph->ident),
| ~~^~~~~~~
liboping.c:694:25: error: conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} may change value [-Werror=conversion]
694 | .icmp_seq = htons (ph->sequence),
| ~~^~~~~~~~~~
liboping.c:709:11: error: conversion from 'ssize_t' {aka 'long int'} to 'int' may change value [-Werror=conversion]
709 | status = ping_sendto (obj, ph, buf, buflen, fd);
| ^~~~~~~~~~~
liboping.c: In function 'ping_send_one_ipv6':
liboping.c:737:27: error: conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} may change value [-Werror=conversion]
737 | .icmp6_id = htons (ph->ident),
| ~~^~~~~~~
liboping.c:738:27: error: conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} may change value [-Werror=conversion]
738 | .icmp6_seq = htons (ph->sequence),
| ^~~~~~~~~~
liboping.c:741:12: error: conversion from 'size_t' {aka 'long unsigned int'} to 'int' may change value [-Werror=conversion]
741 | datalen = strlen (ph->data);
| ^~~~~~
liboping.c:742:27: error: conversion to 'long unsigned int' from 'int' may change the sign of the result [-Werror=sign-conversion]
742 | buflen = sizeof (*icmp6) + datalen;
| ^
liboping.c:747:26: error: conversion to 'size_t' {aka 'long unsigned int'} from 'int' may change the sign of the result [-Werror=sign-conversion]
747 | memcpy (data, ph->data, datalen);
| ^~~~~~~
liboping.c:753:38: error: conversion to 'size_t' {aka 'long unsigned int'} from 'int' may change the sign of the result [-Werror=sign-conversion]
753 | status = ping_sendto (obj, ph, buf, buflen, fd);
| ^~~~~~
liboping.c:753:11: error: conversion from 'ssize_t' {aka 'long int'} to 'int' may change value [-Werror=conversion]
753 | status = ping_sendto (obj, ph, buf, buflen, fd);
| ^~~~~~~~~~~
liboping.c: In function 'ping_open_socket':
liboping.c:1033:39: error: conversion from 'size_t' {aka 'long unsigned int'} to 'socklen_t' {aka 'unsigned int'} may change value [-Werror=conversion]
1033 | obj->device, strlen (obj->device) + 1) != 0)
| ~~~~~~~~~~~~~~~~~~~~~^

liboping.c: In function 'ping_iterator_get_info':
liboping.c:1838:6: error: conversion from 'size_t' {aka 'long unsigned int'} to 'socklen_t' {aka 'unsigned int'} may change value [-Werror=conversion]
1838 | *buffer_len,
| ^~~~~~~~~~~
cc1: all warnings being treated as errors
I use linux x86_64 with gcc-10 and glibc.
On Linux with musl-libc there is one more error:
liboping.c: In function 'ping_receive_one':
liboping.c:509:11: error: unsigned conversion from 'long int' to 'long unsigned int' changes value from '-8' to '18446744073709551608' [-Werror=sign-conversio]
509 | cmsg = CMSG_NXTHDR (&msghdr, cmsg))
| ^~~~~~~~~~~
liboping.c:509:11: error: unsigned conversion from 'long int' to 'long unsigned int' changes value from '-8' to '18446744073709551608' [-Werror=sign-conversio]
Could you try to correct the source using CFLAGS=-Wconversion -Wsign-conversion -Werror -pedantic-errors"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant