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. _______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice