Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: refactor memstream for "print -v"
On 2016/01/06, at 2:58, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author