[Libvir] Strange warnings with gcc 4.1.2

This is with libvirt from CVS. They don't look like errors to me though... ------------ In function ‘open’, inlined from ‘readFile’ at virsh.c:850: /usr/include/bits/fcntl2.h:45: error: call to ‘__open_too_many_args’ declared with attribute error: open can be called either with 2 or 3 arguments, not more /usr/include/bits/fcntl2.h:51: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT in second argument needs 3 arguments The code in question is: if ((fd = open(filename, O_RDONLY)) == -1) { Not a newly created file, so mode isn't needed AFAICS. ------------ In function ‘read’, inlined from ‘readFile’ at virsh.c:864: /usr/include/bits/unistd.h:43: warning: call to ‘__read_chk_warn’ declared with attribute warning: read called with bigger length than size of the destination buffer The code in question is: char buffer[1024]; char *new; int ret; if ((ret = read(fd, buffer, sizeof(buffer))) == 0) break; Also seems correct to me. ------------ Other warnings: virsh.c: In function ‘cmdSchedinfo’: virsh.c:1138: warning: ‘weight’ may be used uninitialized in this function virsh.c:1140: warning: ‘cap’ may be used uninitialized in this function For some reason gcc appears to have lots its ability to do the data flow analysis to find out that these warnings are bogus. In any case the fix is trivial: Index: src/virsh.c =================================================================== RCS file: /data/cvs/libvirt/src/virsh.c,v retrieving revision 1.105 diff -u -r1.105 virsh.c --- src/virsh.c 6 Nov 2007 09:41:18 -0000 1.105 +++ src/virsh.c 7 Nov 2007 12:37:07 -0000 @@ -1135,9 +1135,9 @@ int nr_inputparams = 0; int inputparams = 0; int weightfound = 0; - int weight; + int weight = 0; int capfound = 0; - int cap; + int cap = 0; char str_weight[] = "weight"; char str_cap[] = "cap"; int ret_val = FALSE; Rich. -- Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/ Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 03798903

"Richard W.M. Jones" <rjones@redhat.com> wrote:
This is with libvirt from CVS. They don't look like errors to me though...
------------ In function ‘open’, inlined from ‘readFile’ at virsh.c:850: /usr/include/bits/fcntl2.h:45: error: call to ‘__open_too_many_args’ declared with attribute error: open can be called either with 2 or 3 arguments, not more /usr/include/bits/fcntl2.h:51: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT in second argument needs 3 arguments
The code in question is:
if ((fd = open(filename, O_RDONLY)) == -1) {
Not a newly created file, so mode isn't needed AFAICS.
Hi Rich, Could it be that you need an glibc update? That should pull in headers to fix that. With rawhide, I get no such warning. I like that new open-with-O_CREAT-requires-mode-arg check. It has already caught a bug in the just-released gettext-0.17.

"Richard W.M. Jones" <rjones@redhat.com> wrote:
Other warnings:
virsh.c: In function ‘cmdSchedinfo’: virsh.c:1138: warning: ‘weight’ may be used uninitialized in this function virsh.c:1140: warning: ‘cap’ may be used uninitialized in this function
For some reason gcc appears to have lots its ability to do the data flow analysis to find out that these warnings are bogus. In any case the fix is trivial:
Yeah, annoying. But I'm not sure it's even possible for the compiler to discover that one. But something good did come of it: when I was looking at it yesterday. I noticed bugs in that use of strtol. E.g., the caller silently truncates a 64-bit long value to the "int" return value. Also, it doesn't detect overflow. Will send a patch later today, unless someone else wants to do it.

OK, this was a false alarm. I had ccache[1] installed and it seems like it might have been caching an old intermediate file. `rpm -e ccache' fixed this. Rich. [1] http://ccache.samba.org/ -- Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/ Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 03798903
participants (2)
-
Jim Meyering
-
Richard W.M. Jones