On Wed, Feb 20, 2013 at 7:54 AM, julien2412 <serval2412@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
Context
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.