Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Norbert Thiebaud wrote
On Wed, Feb 20, 2013 at 7:54 AM, julien2412 <

serval2412@

> 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.

Thank you Norbert for the explanation.
As I indicated in my previous message, I would have been ready to revert my
commit but it seems Stephan fixed the whole thing, see
https://gerrit.libreoffice.org/gitweb?p=core.git;a=commitdiff;h=b6ff19fba3a1a6d65134539a71d7a8df0e35d4ff.

Julien
PS : I thought I had found something useful but I must definitely forget
about {0} initialization since it must be used far more carefully than I
expected :-)



--
View this message in context: 
http://nabble.documentfoundation.org/Re-Libreoffice-commits-core-git-desktop-source-tp4038892p4039132.html
Sent from the Dev mailing list archive at Nabble.com.

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.