mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Jens Gustedt <jens.gustedt@inria.fr>
To: musl@lists.openwall.com
Subject: Re: [PATCH] bugfix: initialize a state variable in lio_wait
Date: Sun, 16 Jun 2013 09:22:51 +0200	[thread overview]
Message-ID: <1371367371.16425.363.camel@eris.loria.fr> (raw)
In-Reply-To: <20130616054006.GJ29800@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 2369 bytes --]

Hello,

Am Sonntag, den 16.06.2013, 01:40 -0400 schrieb Rich Felker:
> On Sun, Jun 16, 2013 at 12:16:27AM +0200, Szabolcs Nagy wrote:
> > * Jens Gustedt <Jens.Gustedt@inria.fr> [2013-06-16 00:01:20 +0200]:
> > > got_err was only set to 1 in case of error, but never written
> > > otherwise.
> > 
> > i wonder why gcc -Wmaybe-uninitialized does not catch this
> 
> Indeed, this is very strange. Anyway, I'm committing the fix.

Looking a bit deeper into it, I think this is not only strange but
suspicious.

First, this means that we have not enough coverage for the aio
routines to find simple bugs like that one. aio isn't much used,
obviously.

But then I also checked with clang, and it doesn't find this
either. First, I thought that the control flow surrounding this must
be fundamentally flawed if the compilers aren't capable to track such
simple cases of uninitialized variables. But even by simplifying, it
doesn't trigger, so I am not sure what is going on.

It makes not much sense to me to have an infinite loop at the
outside. I think the control flow should merely be something as
below. Still I am not sure that the strategy of continuing after an
error has been detected is paying something. I would be more in favor
in erroring out as early as possible and return err in errno to let
the application know that there was a problem. Waiting until we
checked everybody and then returning EIO is throwing away information.

Jens

static int lio_wait(struct lio_state *st)
{
  int got_err = 0;
  struct aiocb **const cbs = st->cbs;

  for (int i=0, cnt = st->cnt; i<cnt; i++) {
    if (cbs[i]) {
    RETRY:;
      switch(aio_error(cbs[i])) {
      case EINPROGRESS:
        if (aio_suspend((void *)cbs, cnt, 0))
          return -1;
        else
          goto RETRY;
      case 0:
        break;
      default:
        got_err=1;
        cbs[i] = 0;
        break;
      }
    }
  }
  if (got_err) {
    errno = EIO;
    return -1;
  } else
    return 0;
}



-- 
:: INRIA Nancy Grand Est :: http://www.loria.fr/~gustedt/   ::
:: AlGorille ::::::::::::::: office Nancy : +33 383593090   ::
:: ICube :::::::::::::: office Strasbourg : +33 368854536   ::
:: ::::::::::::::::::::::::::: gsm France : +33 651400183   ::
:: :::::::::::::::::::: gsm international : +49 15737185122 ::



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2013-06-16  7:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-15 22:01 Jens Gustedt
2013-06-15 22:16 ` Szabolcs Nagy
2013-06-16  5:40   ` Rich Felker
2013-06-16  7:22     ` Jens Gustedt [this message]
2013-06-16  9:31       ` Jens Gustedt
2013-06-16 10:18         ` Justin Cormack
2013-06-16 10:43           ` valgrind problems Jens Gustedt
2013-06-16 11:39             ` Szabolcs Nagy
2013-06-16 14:16               ` Jens Gustedt
2013-06-16 14:36                 ` Rich Felker
2013-06-16 14:31             ` Rich Felker
2013-06-16 15:26               ` Jens Gustedt
2013-06-16 15:31                 ` Rich Felker
2013-06-16 15:58                   ` Jens Gustedt
2013-06-16 16:04                     ` Rich Felker
2013-06-16 17:39                       ` Jens Gustedt
2013-06-16 19:16                         ` Rich Felker
2013-06-16 19:38                           ` Szabolcs Nagy
2013-06-16 19:41                             ` Rich Felker
2013-06-16 17:40                     ` Szabolcs Nagy
2013-06-16 18:02                       ` Jens Gustedt
2013-06-16 19:25                         ` Szabolcs Nagy
2013-06-16 19:29                           ` Rich Felker
2013-06-16 14:24         ` [PATCH] bugfix: initialize a state variable in lio_wait Rich Felker
2013-06-16 15:48           ` Jens Gustedt
2013-06-16 15:37   ` Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1371367371.16425.363.camel@eris.loria.fr \
    --to=jens.gustedt@inria.fr \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).