Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: Fix use-after-free for print -zf and print -sf



On Tue, Feb 10, 2015 at 10:37 AM, Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
> On Tue, 10 Feb 2015 08:16:56 +0100
> Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>> On Tue, Feb 10, 2015 at 8:12 AM, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>> >      /* Testing EBADF special-cases >&- redirections */
>> > -    if ((fout != stdout) ? (fclose(fout) != 0) :
>> > +    if (fout && (fout != stdout) ? (fclose(fout) != 0) :
>>
>> Do I need an extra set of parens here? C precedence rules are fun.
>>
>
> https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence
>
> "&&" is higher precedence than ?: so this looks OK.
>
> I suppose it's at the point where a lot of people would decide it needed
> expanding into something clearer, but it's a reasonable extension of
> what was there before.  Can't see a problem with it.

Oops, actually I think I do need it, since I want fout being NULL to
short circuit the whole if statement to false, and currently it's
interpreted as if ((fout && (fout != stdout)) ? .. : ..), resulting in
a call to fflush(NULL) which flushes all open output buffers. I should
probably have quoted both lines of the if. :)

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author