zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: PATCH: Fix use-after-free for print -zf and print -sf
Date: Tue, 10 Feb 2015 11:38:21 +0000	[thread overview]
Message-ID: <20150210113821.36e1b7ed@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <CAHYJk3Q3AMx_+TxVKq0mx6jhCEGCxSDPoJ3K1PPm6tAY3nDUww@mail.gmail.com>

On Tue, 10 Feb 2015 12:32:52 +0100
Mikael Magnusson <mikachu@gmail.com> 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


      reply	other threads:[~2015-02-10 11:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-10  7:12 Mikael Magnusson
2015-02-10  7:16 ` Mikael Magnusson
2015-02-10  9:37   ` Peter Stephenson
2015-02-10 11:13     ` Mikael Magnusson
2015-02-10 11:18       ` Peter Stephenson
2015-02-10 11:32         ` Mikael Magnusson
2015-02-10 11:38           ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150210113821.36e1b7ed@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).