collectd/collectd — Issue #49: Compilation with clang fails (with -Werror due to tautological compare)
Author: neverpanic
Created: 2012-03-10 01:16:01+00:00
State: open

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:

```patch
--- 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: "
```