From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9282 invoked by alias); 6 Jan 2016 06:02:51 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37511 Received: (qmail 28704 invoked from network); 6 Jan 2016 06:02:48 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Biglobe-Sender: Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: PATCH: refactor memstream for "print -v" From: "Jun T." In-Reply-To: <160105095834.ZM3834@torch.brasslantern.com> Date: Wed, 6 Jan 2016 15:02:19 +0900 Content-Transfer-Encoding: 7bit Message-Id: References: <160104231830.ZM20279@torch.brasslantern.com> <4052A17B-0432-44A7-8A84-F615FD836FCF@kba.biglobe.ne.jp> <160105095834.ZM3834@torch.brasslantern.com> To: "zsh-workers@zsh.org" X-Mailer: Apple Mail (2.1510) X-Biglobe-Spnum: 52877 On 2016/01/06, at 2:58, Bart Schaefer wrote: > but I was > trying to be consistent with open_memstream() which maintains a NUL at > the end of the buffer it manages. Sorry, then I misunderstood what you wanted to achieve. I just thought the simpler the better. > Maybe it should be (long) though? And I suppose the comparison should > explicitly be == -1 rather than < 0 in case mcount is ridiculusly big. Yes. Moreover, if '== -1' is used, casting by (long) may not be necessary, because if n is of type size_t, (x ? n : -1) == -1 --> (x ? n : (size_t)-1) == (size_t)-1 is true only if x is false or n==(size_t)-1. On my Mac (and probably on most systems) the following seems to be equivalent to the above: (x ? (long)n : -1) == -1 --> (x ? (long)n : (long)-1) == (long)-1 but in theory signed --> unsigned is safer than unsigned --> signed. So not casting (or using (size_t)-1) may be better? BTW, how about modifying READ_MSTREAM so that READ_MSTREAM(buf,rcount,fout) == -1 can be replaced by (rcount = READ_MSTREAM(buf,fout)) == -1 or !READ_MSTREAM(buf,rcount,fout)