bug-gawk
[Top][All Lists]
Advanced

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

Re: Undetected fatal errors from redirected print


From: Andrew J. Schorr
Subject: Re: Undetected fatal errors from redirected print
Date: Sat, 27 Nov 2021 10:33:20 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

On Sat, Nov 27, 2021 at 04:08:28AM -0500, Miguel Pineiro Jr. wrote:
> Hi, Andy
> 
> On Fri, Nov 26, 2021, at 11:28 AM, Andrew J. Schorr wrote:
> > Interesting. Do we actually need the goto in efwrite, or can we just
> > skip the fwrite call if count is 0? That way, we can avoid the ugliness
> > of testing the first character of `from'. See the attached patch.
> 
> Testing the first character of from, I agree, is ugly. Though effective, it's 
> cryptic and arbitrary.
> 
> The goto isn't necessary, but I think it actually makes the code and the 
> intent very easy to follow: If this condition is true, jump to the flush.
> 
> I see two issues with your patch:
> 
> 1. If I understand your intent, efwrite should flush when count is 0, but it 
> doesn't. The flushing conditional expression needs OR-ing with "count == 0". 

Well, but the call to efwrite has the has the final argument `flush' set to
true, so the the "if" condition is going to succeed when rp is non-NULL.
The stdout case is a bit tricker, since it could fail if it's not a tty.
So you've got a valid point there if we want to use efwrite to flush stdout
from close_io. What about stderr?


> 2. do_printrec, do_print, and do_printf may call efwrite with a zero count. 
> In those instances,
> flushing would be forced where before it never occurred (fwrite with a zero 
> count is a no-op).

My patch doesn't force flushing at all. It merely skips the call
to fwrite (or gawk_fwrite) when there's nothing to write.

But if we're going to want to use this to flush stdout & stderr, then I agree
that my patch is not suitable.

Regards,
Andy



reply via email to

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