Skip to contentSkip to conversation

avoid compilation warning/errors on up to date compilers/glibc

PATCH [email protected] 3 participants 5 messages Jun 17, 2009 – Jun 18, 2009 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 79 lines · ----- "Anthony Liguori
Quoted 1 line · Jean-Christophe Dubois

Some system calls are now requiring to have their return value

checked.

Quoted 2 lines

Without this a warning is emitted and in the case a qemu an error

is

Quoted 6 lines

triggered as qemu is considering warnings as errors.

For example:

block/cow.c: In function ‘cow_create’:
block/cow.c:251: error: ignoring return value of ‘write’, declared

with

Quoted 2 lines

attribute warn_unused_result
block/cow.c:253: error: ignoring return value of ‘ftruncate’,

declared

Quoted 11 lines

with attribute warn_unused_result

This is an attempt at removing all these warnings to allow a clean compilation with up to date compilers/distributions.

The second version fixes an error detected by Stuart Brady as well as some coding style issues. Note however that some of the modified files don't follow the qemu coding style (using tabs instead of spaces).

The Third version add one ftruncate() system call error handling

that

block.c int bdrv_open2(BlockDriverState *bs, const char

Quoted 26 lines

was missing from V2 (in block/vvfat.c).

---
 block.c           |    3 ++-
 block/bochs.c     |    3 ++-
 block/cow.c       |   12 ++++++++++--
 block/qcow.c      |   22 ++++++++++++++++------
 block/qcow2.c     |   37 +++++++++++++++++++++++++++++--------
 block/raw-posix.c |    9 ++++++---
 block/vmdk.c      |   38 ++++++++++++++++++++++++++++----------
 block/vvfat.c     |   24 +++++++++++++++++-------
 linux-user/mmap.c |    7 +++++--
 linux-user/path.c |    6 +++++-
 osdep.c           |    5 ++++-
 slirp/misc.c      |    3 ++-
 usb-linux.c       |    3 +--
 vl.c              |   14 ++++++++++----
 14 files changed, 137 insertions(+), 49 deletions(-)
block.c +0 -0
index aca5a6d..c78d66a 100644
@@ -371,7 +371,8 @@ int bdrv_open2(BlockDriverState *bs, const char

*filename, int flags,

block.c int bdrv_open2(BlockDriverState *bs, const char · line 378

Quoted 9 lines
block.c +2 -1
             snprintf(backing_filename, sizeof(backing_filename),
                      "%s", filename);
         else
-            realpath(filename, backing_filename);
+            if (!realpath(filename, backing_filename))
+                return -1;
 
         bdrv_qcow2 = bdrv_find_format("qcow2");
         options = parse_option_parameters("",

bdrv_qcow2->create_options, NULL);

block/bochs.c static inline int

Quoted 5 lines
block/bochs.c +0 -0
index bac81c4..0d614eb 100644
@@ -199,7 +199,8 @@ static inline int

seek_to_sector(BlockDriverState *bs, int64_t sector_num)

block/bochs.c static inline int · line 204

Quoted 7 lines
block/bochs.c +2 -1
     // read in bitmap for current extent
     lseek(s->fd, bitmap_offset + (extent_offset / 8), SEEK_SET);
 
-    read(s->fd, &bitmap_entry, 1);
+    if (read(s->fd, &bitmap_entry, 1) != 1)
+        return -1; // not allocated
 
Quoted 5 lines

This is no more correct than before. read() can return EINTR and that

should be handled appropriately. Elsewhere, read() can return partial

results and we ought to handle that properly.

It handles all cases except EINTR. And in the actual code base EINTR and __all other__ error cases are not handled. So as of today EINTR is not handled propely (as well as all other error cases). So this consider EINTR as an error when it could be handled in a nicer way. Previously no ERRORS were considered as an error. What is best?

Quoted 2 lines

Using -D_FORTIFY_SOURCES=0 will eliminate these warnings. If we're going to fix these things, we should fix them properly.

It just hides the problem and fix nothing but the compilation. ERRORS will still be ignored/discarded without any warning. If the glibc designers are insisting on the fact that some system calls should have their return value checked there must be a reason. Is this really the best practice here (to just ignore errors)?

Quoted 3 lines

Regards,

Anthony Liguori

#2 lore raw
Quoted 9 lines
Quoted 3 lines

This is no more correct than before. read() can return EINTR and that should be handled appropriately. Elsewhere, read() can return partial results and we ought to handle that properly.

It handles all cases except EINTR. And in the actual code base EINTR and __all other__ error cases are not handled. So as of today EINTR is not handled propely (as well as all other error cases). So this consider EINTR as an error when it could be handled in a nicer way. Previously no ERRORS were considered as an error. What is best?

The original is the lesser wevil because it is obviously wrong. Your patch looks like it does error handling and avoids generates warnings, but still does not work correctty.

Quoted 4 lines
Quoted 2 lines

Using -D_FORTIFY_SOURCES=0 will eliminate these warnings. If we're going to fix these things, we should fix them properly.

It just hides the problem and fix nothing but the compilation.

Your patch just makes the bug more subtle and harder to spot.

Paul

#3 lore raw

Le mercredi 17 juin 2009 16:03:51, vous avez écrit :

Quoted 14 lines
Quoted 9 lines
Quoted 3 lines

This is no more correct than before. read() can return EINTR and that should be handled appropriately. Elsewhere, read() can return partial results and we ought to handle that properly.

It handles all cases except EINTR. And in the actual code base EINTR and __all other__ error cases are not handled. So as of today EINTR is not handled propely (as well as all other error cases). So this consider EINTR as an error when it could be handled in a nicer way. Previously no ERRORS were considered as an error. What is best?

The original is the lesser wevil because it is obviously wrong. Your patch looks like it does error handling and avoids generates warnings, but still does not work correctty.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Using -D_FORTIFY_SOURCES=0 will eliminate these warnings. If we're going to fix these things, we should fix them properly.

It just hides the problem and fix nothing but the compilation.

Your patch just makes the bug more subtle and harder to spot.

I guess this is a matter of point of view.

Is it harder to find a bug when:
1) you are silencing compilation warning/errors AND ignoring all runtime errors (also silencing future warnings/errors).
or 2) You are considering recoverable errors as non recoverable errors.

You make your call.

Anyway fixing all those "bad" calls the "proper" way will be quite involved.

BTW are you sure that EINTR and EAGAIN are correctly handled all over the source code? What about partial read/write?

JC

Quoted 2 lines

Paul

#4 lore raw
Quoted 16 lines · On Wed, 17 Jun 2009 20:41:14 +0200 "Jean-Christophe Dubois"…

Le mercredi 17 juin 2009 16:03:51, vous avez écrit :

Quoted 15 lines
Quoted 10 lines
Quoted 3 lines

This is no more correct than before. read() can return EINTR and that should be handled appropriately. Elsewhere, read() can return partial results and we ought to handle that properly.

It handles all cases except EINTR. And in the actual code base EINTR and __all other__ error cases are not handled. So as of today EINTR is not handled propely (as well as all other error cases). So this consider EINTR as an error when it could be handled in a nicer way. Previously no ERRORS were considered as an error. What is best?

The original is the lesser wevil because it is obviously wrong. Your patch looks like it does error handling and avoids generates warnings, but still does not work correctty.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Using -D_FORTIFY_SOURCES=0 will eliminate these warnings. If we're going to fix these things, we should fix them properly.

It just hides the problem and fix nothing but the compilation.

Your patch just makes the bug more subtle and harder to spot.

I guess this is a matter of point of view.

I don't think it's a point of view, today we have a warning and we
know something is not ok. With this patch we won't have the warning anymore but the solution is not what it should be.

Can't we have wrappers to read() and write() that does the right
thing and use them everywhere?

Quoted 3 lines

Is it harder to find a bug when:
1) you are silencing compilation warning/errors AND ignoring all runtime errors (also silencing future warnings/errors).

My impression is that Anthony's tip is for you get it built, not
a final solution to the problem.

Quoted 2 lines

or 2) You are considering recoverable errors as non recoverable errors.

qemu_read() and qemu_write() could handle both.

Quoted 2 lines

BTW are you sure that EINTR and EAGAIN are correctly handled all over the source code? What about partial read/write?

I have no idea, but if they are not they should be fixed then.

#5 lore raw
Quoted 3 lines · ----- "Luiz Capitulino

I don't think it's a point of view, today we have a warning and we
know something is not ok. With this patch we won't have the warning anymore but the solution is not what it should be.

If you silence GCC there will not be any warning anymore either.

Quoted 2 lines

Can't we have wrappers to read() and write() that does the right
thing and use them everywhere?

It is already proposed. See version 4 of the patch.