NetBSD-Bugs archive

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

Re: bin/48183: Example in man write(2) causes endless loop



The following reply was made to PR bin/48183; it has been noted by GNATS.

From: Valery Ushakov <uwe%stderr.spb.ru@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: bin/48183: Example in man write(2) causes endless loop
Date: Fri, 6 Sep 2013 03:41:52 +0400

 > On Wed, Sep 04, 2013 at 11:30:00PM +0000, manuel%bsdstammtisch.at@localhost 
 > wrote:
 > > >Number:         48183
 > > >Category:       bin
 > > >Synopsis:       Example in man write(2) causes endless loop
 > ...
 > > The manpage of pread says:
 > > 
 > > Proper loops should use
 > > while ((nr = write(fd, buf, sizeof(buf))) != -1 && nr != 0)
 > > 
 > > which is clearly an endless loop. Say nr = 512 and the write is
 > > successful, then 512 != -1 && n1 !=0  is true.
 > 
 > That whole section is fud.
 > It would only ever be a problem if the program had a buffer large enough.
 > That is a 2GB buffer on a system with 32bit size_t!
 > The application would also know that it was doing very large writes.
 > In most programs the write() calls are small (relative to size_t).
 > I suspect it is only a problem for systems with 16bit size_t and 32bit ptr.
 >
 > The 'partial write' support would be more useful - especially for writev().
 
 The text is self-contradictory as using implementation-defined
 behaviour (nbytes > SSZIZE_MAX) is not something you would do for
 "maximum portability".
 
 Manual should explicitly say that for nbytes > SSIZE_MAX the result is
 implementation-defined.
 
 Name of the "nr" variable suggests that the example was copy-pasted
 from read(2), which is indeed the case.  The loops, as written, don't
 make much sense for write(2).
 
 -uwe
 


Home | Main Index | Thread Index | Old Index