Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

clang fails in network.c (with -Werror due to tautological compare) #49

Closed
neverpanic opened this Issue · 2 comments

2 participants

@neverpanic

When compiled with clang 3.1, the network plugin fails with:

libtool: compile:  /usr/bin/clang -DHAVE_CONFIG_H -I. -DPREFIX=\"/opt/local\" -DCONFIGFILE=\"/opt/local/etc/collectd.conf\" -DLOCALSTATEDIR=\"/opt/local/var\" -DPKGLOCALSTATEDIR=\"/opt/local/var/lib/collectd\" -DPIDFILE=\"/opt/local/var/run/collectd.pid\" -DPLUGINDIR=\"/opt/local/lib/collectd\" -DPKGDATADIR=\"/opt/local/share/collectd\" -I/opt/local/include -I/opt/local/include -Wall -Werror -pipe -O2 -D_GCRYPT_IN_LIBGCRYPT=1 -arch x86_64 -MT network_la-network.lo -MD -MP -MF .deps/network_la-network.Tpo -c network.c  -fno-common -DPIC -o .libs/network_la-network.o
network.c:708:18: error: comparison of unsigned expression < 0 is always false [-Werror,-Wtautological-compare]
        if ((buffer_len < 0) || (buffer_len < exp_size))
             ~~~~~~~~~~ ^ ~
network.c:793:18: error: comparison of unsigned expression < 0 is always false [-Werror,-Wtautological-compare]
        if ((buffer_len < 0) || ((size_t) buffer_len < exp_size))
             ~~~~~~~~~~ ^ ~
network.c:832:18: error: comparison of unsigned expression < 0 is always false [-Werror,-Wtautological-compare]
        if ((buffer_len < 0) || (buffer_len < header_size))
             ~~~~~~~~~~ ^ ~

Since ISO C99 specifies size_t to be unsigned I think this comparison can safely be dropped:

--- src/network.c.orig  2012-03-10 02:11:29.000000000 +0100
+++ src/network.c   2012-03-10 02:13:01.000000000 +0100
@@ -705,7 +705,7 @@

    exp_size = 3 * sizeof (uint16_t)
        + pkg_numval * (sizeof (uint8_t) + sizeof (value_t));
-   if ((buffer_len < 0) || (buffer_len < exp_size))
+   if (buffer_len < exp_size)
    {
        WARNING ("network plugin: parse_part_values: "
                "Packet too short: "
@@ -790,7 +790,7 @@

    uint16_t pkg_length;

-   if ((buffer_len < 0) || ((size_t) buffer_len < exp_size))
+   if ((size_t) buffer_len < exp_size)
    {
        WARNING ("network plugin: parse_part_number: "
                "Packet too short: "
@@ -829,7 +829,7 @@

    uint16_t pkg_length;

-   if ((buffer_len < 0) || (buffer_len < header_size))
+   if (buffer_len < header_size)
    {
        WARNING ("network plugin: parse_part_string: "
                "Packet too short: "
@octo octo was assigned
@octo
Owner

Sounds like a legacy from a previous int to size_t conversion.

@octo octo referenced this issue from a commit
@octo octo network plugin: Fix compiler warnings.
Resolves GitHub issue #49.
b21e598
@octo
Owner

Fixed, thanks for the pointer!

—octo

@octo octo closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.