[mythtv] audio write() error check

Bruce Markey bjm at lvcm.com
Mon Nov 10 17:46:22 EST 2003


mythtv at cvs.mythtv.org wrote:
> ----------------------------------------------------------------------------
> Changes committed by ijr on Mon Nov 10 21:44:47 2003
...
>    in mythtv/libs/libmyth:
>         audiooutputoss.cpp 
...
> Small logic fix in audiooutputoss by Manu.
...

Isaac, can you tale a look at this again?

Revision 1.9

    while ((written < size) && 
           ((lw = write(audiofd, tmpbuf, size - written)) > 0))
    {
        if (lw == -1)
        {
            cerr << "Error writing to audio device, exiting\n";
            close(audiofd);
            audiofd = -1;
            return;
        }
        written += lw;
        tmpbuf += lw;
    }

"lw" is the return value from the write. The first thing to do
is to check if there was an error. If so, handle the error and
don't modify the variables. Seems reasonable.

Revision 1.10

    while ((written < size) && 
           ((lw = write(audiofd, tmpbuf, size - written)) > 0))
    {
        written += lw;
        tmpbuf += lw;
    }

    if (lw < 0)
    {
        perror("Writing to audio device");
        close(audiofd);
        audiofd = -1;
        return;
    }

Here if there is a write error, -1 is added to written and
tmpbuf and then it continues to loop (possibly forever if there
is a persistent cause of the write error). Only after the while
loop falls through does it check to see if the last value for
"lw" was an error. However, written needs to grow to >= size
so the loop would never fall through when written was shrunk
by -1.

I'm not saying that there might not be a problem when handling
errors writing to audiofd but this code is not a valid solution
for whatever the problem might be.

--  bjm





More information about the mythtv-dev mailing list