Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

rrdtool.c:1059: error: passing argument 4 of ‘qsort’ from incompatible pointer type #287

Closed
ymettier opened this Issue · 3 comments

2 participants

@ymettier

Hello,

On Redhat 6 with gcc 4.4.6, I have this error (notice the -Werror=uninitialized) :

./clean.sh ; ./build.sh ; ./configure CFLAGS="-O0 -g -Werror=uninitialized" CXXFLAGS="-O0 -g -Werror=uninitialized" --enable-debug
[...]
make
[...]
/bin/sh ../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.  -DPREFIX='"/opt/collectd"' -DCONFIGFILE='"/opt/collectd/etc/collectd.conf"' -DLOCALSTATEDIR='"/opt/collectd/var"' -DPKGLOCALSTATEDIR='"/opt/collectd/var/lib/collectd"' -DPIDFILE='"/opt/collectd/var/run/collectd.pid"' -DPLUGINDIR='"/opt/collectd/lib/collectd"' -DPKGDATADIR='"/opt/collectd/share/collectd"'  -Wall -Werror  -O0 -g -Werror=uninitialized -MT rrdtool_la-rrdtool.lo -MD -MP -MF .deps/rrdtool_la-rrdtool.Tpo -c -o rrdtool_la-rrdtool.lo `test -f 'rrdtool.c' || echo './'`rrdtool.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -DPREFIX=\"/opt/collectd\" -DCONFIGFILE=\"/opt/collectd/etc/collectd.conf\" -DLOCALSTATEDIR=\"/opt/collectd/var\" -DPKGLOCALSTATEDIR=\"/opt/collectd/var/lib/collectd\" -DPIDFILE=\"/opt/collectd/var/run/collectd.pid\" -DPLUGINDIR=\"/opt/collectd/lib/collectd\" -DPKGDATADIR=\"/opt/collectd/share/collectd\" -Wall -Werror -O0 -g -Werror=uninitialized -MT rrdtool_la-rrdtool.lo -MD -MP -MF .deps/rrdtool_la-rrdtool.Tpo -c rrdtool.c  -fPIC -DPIC -o .libs/rrdtool_la-rrdtool.o
cc1: warnings being treated as errors
rrdtool.c: In function ‘rrd_config’:
rrdtool.c:1059: error: passing argument 4 of ‘qsort’ from incompatible pointer type
/usr/include/stdlib.h:761: note: expected ‘__compar_fn_t’ but argument is of type ‘int (*)(void *, void *)’
make[3]: *** [rrdtool_la-rrdtool.lo] Error 1

If I cast the 4th argument, it will compile (and I will have the same error and same fix in configfile.c)

        qsort (/* base = */ rrdcreate_config.timespans,
                /* nmemb  = */ rrdcreate_config.timespans_num,
                /* size   = */ sizeof (rrdcreate_config.timespans[0]),
                /* compar = */ (__compar_fn_t) rrd_compare_numeric);

I could also cast (int (*) (__const void *, __const void *)) instead of (__compar_fn_t).

However, (int (*) (const void *, const void *)) does not work.

Because I found nothing standard, and because I do not have this problem without -Werror=uninitialized, I wonder if this should be fixed and how.

Regards,
Yves

@octo
Owner

Hi Yves,

I believe that rrd_compare_numeric() conforms to POSIX, i.e. it conforms to http://pubs.opengroup.org/onlinepubs/9699919799/functions/qsort.html.

I don't know what __const does, but my guess is that this is a bug that --Werror=uninitialized somehow influences __const. I don't think that we should "fix" this in collectd though.

Best regards,
—octo

@ymettier

Hello,

As far as I understand const and __const, everyone knows const except gcc (the pre-processor I presume).
To have gcc read const, you have to write __const like in /usr/include/*.h

I don't think that we should "fix" this in collectd though.

IMHO, the most important was to write it somewhere so if somebody else complains, maybe (s)he will find this issue first and know what to do.
For me, this issue can now be closed.

Regards,
Yves

@octo
Owner

Alright, thanks :)

@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.