bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] invalid use of errno after ferror


From: Paul Eggert
Subject: Re: [Bug-gnulib] invalid use of errno after ferror
Date: 17 Sep 2003 13:14:39 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Bruno Haible <address@hidden> writes:

> --- getndelim2.c      15 Sep 2003 22:34:18 -0000      1.4
> +++ getndelim2.c      17 Sep 2003 10:25:47 -0000
> @@ -95,12 +95,16 @@
>           }
>       }
>  
> +      /* Clear errno, so that on non-POSIX systems the caller doesn't see a
> +      wrong value of errno when we return -1.  */
> +      errno = 0;
> +
>        c = getc (stream);
>        if (c == EOF)
>       {
>         /* Return partial line, if any.  */
>         if (read_pos == *lineptr)
> -         return -1;
> +         return -1; /* if error occurred, errno is set here */
>         else
>           break;
>       }

Ouch.  There's lots of other code that assumes that getc sets errno.
What non-POSIX systems were you thinking of?

Perhaps it would be better to let sleeping dogs lie, as the bug is not
that serious in this case, and it occurs only on older or nonstandard
systems.  Or, if we do want to fix this sort of problem, we should do
it with a getc wrapper rather than rewriting all the code.



> >     Don't assume ferror sets errno.  Bug reported by Bruno Haible.
> >     * src/cksum.c (cksum): Don't assume ferror sets errno.
> 
> But here you could actually still provide the errno value by calling
> fwriteerror (stdout) instead of ferror (stdout). That's why I added the
> fwriteerror module to gnulib.

I'm reluctant to use fwriteerror.  If a GNU utility finds an error, it
should report the first error that it found, not some other error that
it finds in a fixup action.  Instead of using fwriteerror to paper
over the problem, I'd rather fix the code so that it doesn't lose
errno in the first place.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]