liboping icon indicating copy to clipboard operation
liboping copied to clipboard

-Wconversion -Wsign-conversion -Werror compilation errors

Open iu1j4 opened this issue 4 years ago • 0 comments

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"?

iu1j4 avatar Jan 23 '21 11:01 iu1j4