[Libreoffice-commits] core.git: desktop/source
Norbert Thiebaud
nthiebaud at gmail.com
Thu Feb 21 04:08:13 PST 2013
On Wed, Feb 20, 2013 at 7:54 AM, julien2412 <serval2412 at yahoo.fr> wrote:
>
> Yes I meant it, why? Is it wrong?
> if "pReceiveBuffer" is initialized with 0 for the (sc_nCSASeqLength + 1)
> elements thanks to = {0} initialization, what obvious thing did I miss? Why
> "pReceiveBuffer[nBytes-1] = 0;" would need to stay?
Ok since I added that particular code, let me explain
> - if (nBytes > 0)
> - {
> - pReceiveBuffer[nBytes-1] = 0;
> - }
was needed because the loop before can exit under 2 conditions:
the normal one where a[nBytes - 1] is already 0
or the 'non-normal' one when the recv return 0 (or -1 for that matter)
which mean the pipe got interrupted prematurely, in which case the
buffer would _not_ be 0-terminated
which was relyied upon later.
there is also the case where recv bail out before reading anything at
that point nByte = 0 si of course we do not want to do a[nByte - 1]
and for that case a[0] is set to 0;
initializing the whole buffer is a waste in all case but the corner
case where the pipe get broken.
Note: it is clearly not expected that the pipe close with receiving
a\0 as last character... ortherwise we would already be segfaulting a
lot due to the code aftert that that _assume_ that the buffer is a
0-terminated string.
so there is no particular danger that a valid character would be
overwritten in normal expected cases.
Norbert
More information about the LibreOffice
mailing list