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, 10 Feb 2015 12:32:52 +0100
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> +#ifdef HAVE_OPEN_MEMSTREAM
> +    if (fout)
> +#endif
> +       /* Testing EBADF special-cases >&- redirections */
> +       if ((fout != stdout) ? (fclose(fout) != 0) :
> +           (fflush(fout) != 0 && errno != EBADF)) {
> +           zwarnnam(name, "write error: %e", errno);
> +           ret = 1;
> +       }

This looks fine although based on experience I'd tend to write it as...

#ifdef HAVE_OPEN_MEMSTREAM
    if (fout)
#endif
    {
       /* Testing EBADF special-cases >&- redirections */
       if ((fout != stdout) ? (fclose(fout) != 0) :
           (fflush(fout) != 0 && errno != EBADF)) {
           zwarnnam(name, "write error: %e", errno);
           ret = 1;
       }
    }

for clarity.  The braces are harmless without HAVE_OPEN_MEMSTREAM and
explain the indentation --- otherwise you may well find lint or Coverity
wailing they don't understand the indentation.

(... anyone remember lint ...?)

pws



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