Hi Todd, Todd C. Miller wrote on Mon, Dec 28, 2015 at 10:46:08AM -0700: > On Fri, 25 Dec 2015 00:30:29 +0100, Ingo Schwarze wrote:
>> Besides, i don't see the point in messing with FILE flags at all >> in case of encoding errors. As opposed to fgetwc(3) and fputwc(3), >> the manual doesn't document this fiddling, and POSIX doesn't ask >> for it. No other conversions in printf(3) set the error indicator. >> It isn't required because printf(3) provides a proper error return >> (-1) in the first place. Has anybody ever seen any code calling >> ferror(3) after printf(3)? That just wouldn't make sense. >> Of course, printf(3) can result in the error indicator getting set, >> but only if the underlying low-level write calls fail. > You are correct that neither our man page nor ISO C document > setting the error indicator. I get your expected output on Linux > and Solaris so I think this diff is correct. I wonder if it is > worth documenting that the error indicator is not set in fprintf(3)? I doubt that adding text to that effect would be useful. It would get long and sound confusing. Usually we don't talk about what functions do *not* do, and we don't talk about what standards do *not* require, we just explain what they do. If people think this should be an exception and we should explain explicitly what these functions do not do, i think something like this would be needed. CAVEATS These functions may set the error indicator on the stream if underlying low-level output functions fail. On OpenBSD, they don't set the error indicator themselves, for example if memory allocation fails or character encoding errors are encountered. In general, checking ferror(3) after calling these functions is not useful; instead, use the return value to detect errors. Unless you like this text, i'm not planning to send a patch. > We do have code in our tree that checks ferror() after doing writes > via fprintf. One example src/usr.sbin/smtpd, Is anybody taking care of checking whether anything needs fixing in smtpd? > but I have not done an exhaustive check. Anybody? I'm still kind of swamped... Thanks, Ingo
