This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Ping[3]: [PATCH][BZ #11741] printf should return negative valueon I/O error


On Thu, 15 Nov 2012 23:00:48 -0500, Carlos wrote:
> Your original patch still suffers the same problem, you make
> a change to libio/iowpadn.c that isn't needed?
> 
> diff --git a/libio/iowpadn.c b/libio/iowpadn.c
> index 05632d5..334e01a 100644
> --- a/libio/iowpadn.c
> +++ b/libio/iowpadn.c
> @@ -65,7 +65,7 @@ _IO_wpadn (fp, pad, count)
>        w = _IO_sputn (fp, (char *) padptr, PADSIZE);
>        written += w;
>        if (w != PADSIZE)
> -	return written;
> +	return w <= 0 ? w : written;
>      }
> 
>    if (i > 0)
> ---
> 
> Can you confirm you need this change?
> 

Ah, sorry, I have finally paged in the context of this patch.  The
changes are needed.

_IO_file_xsputn can return EOF if overflow handling fails, i.e.
flushing to the file fails:

@@ -1330,9 +1331,10 @@ _IO_new_file_xsputn (f, data, n)
       _IO_size_t block_size, do_write;
       /* Next flush the (full) buffer. */
       if (_IO_OVERFLOW (f, EOF) == EOF)
-	/* If nothing else has to be written we must not signal the
-	   caller that everything has been written.  */
-	return to_do == 0 ? EOF : n - to_do;
+	/* If nothing else has to be written or nothing has been written, we
+	   must not signal the caller that the call was even partially
+	   successful.  */
+	return (to_do == 0 || to_do == n) ? EOF : n - to_do;
 
       /* Try to maintain alignment: write a whole number of blocks.
 	 dont_write is what gets left over. */

Of course, it doesn't currently since _IO_new_file_write (which is
called in the overflow handling) fails to propagate the error, which
this patch now fixes. In fact, I wasn't sure if xsputn returning 0 was
expected since I was expecting it to return either EOF (0 or error) or
the number of bytes read.  Andreas' response reinforced that and hence
the modified patch.


Siddhesh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]