[Libreoffice-commits] core.git: desktop/source

Lubos Lunak l.lunak at suse.cz
Wed Feb 20 06:41:11 PST 2013


On Wednesday 20 of February 2013, julien2412 [via Document Foundation Mail 
Archive] wrote:
> Lubos Lunak wrote
>
> > On Tuesday 19 of February 2013, Julien Nabet wrote:
> >> diff --git a/desktop/source/app/officeipcthread.cxx
> >> b/desktop/source/app/officeipcthread.cxx index 8db7946..445ccb4 100644
> >> --- a/desktop/source/app/officeipcthread.cxx
> >> +++ b/desktop/source/app/officeipcthread.cxx
> >> @@ -497,23 +497,17 @@ OfficeIPCThread::Status
> >> OfficeIPCThread::EnableOfficeIPCThread() else if(
> >> pThread->maPipe.create( aPipeIdent.getStr(), osl_Pipe_OPEN, rSecurity ))
> >> // Creation not successfull, now we try to connect {
> >>              osl::StreamPipe aStreamPipe(pThread->maPipe.getHandle());
> >> -            char pReceiveBuffer[sc_nCSASeqLength + 1];
> >> +            char pReceiveBuffer[sc_nCSASeqLength + 1] = {0};
> >>              int nResult = 0;
> >>              int nBytes = 0;
> >>              int nBufSz = sc_nCSASeqLength + 1;
> >>              // read byte per byte
> >> -            pReceiveBuffer[0] = 0;
> >>              while ((nResult=aStreamPipe.recv( pReceiveBuffer+nBytes,
> >> nBufSz-nBytes))>0) { nBytes += nResult;
> >>                  if (pReceiveBuffer[nBytes-1]=='\0') {
> >>                      break;
> >>                  }
> >>              }
> >> -            /* make sure the buffer is \0 terminated */
> >> -            if (nBytes > 0)
> >> -            {
> >> -                pReceiveBuffer[nBytes-1] = 0;
> >> -            }
> >
> >  Did you really mean to remove this part?
>
> Hi Lubos,
>
> 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?

 Sorry, I did not realize that = { 0 } actually clears the rest of the array. 
And I do not quite understand why clearing an entire array is supposed to be 
a good way to initialize it when just setting the last one to 0 is enough.

> Why "pReceiveBuffer[nBytes-1] = 0;" would need to stay?

 If I'm reading the code correctly, "nBytes-1" is not the position after the 
read data, but the last read item. Which should mean that the repeated recv() 
may rewrite all the 0's from the initialization. That rather begs the 
question why it changes the last read item instead of terminating it, so the 
code may have been already broken to begin with.

-- 
 Lubos Lunak
 l.lunak at suse.cz




--
View this message in context: http://nabble.documentfoundation.org/Re-Libreoffice-commits-core-git-desktop-source-tp4038892p4038899.html
Sent from the Dev mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20130220/59b3a05a/attachment.html>


More information about the LibreOffice mailing list