[Common-dev] [CR-common] viewsrc string allocation fix
Greg Wright gwright at real.comLook ok. --greg. ----- Original Message ----- From: "Ryan Gammon" <rgammon at real.com> To: "Tom Marshall" <tmarshall at real.com> Cc: <dev at common.helixcommunity.org> Sent: Tuesday, May 11, 2004 7:03 PM Subject: Re: [Common-dev] [CR-common] viewsrc string allocation fix > Tom Marshall wrote: > > >Isn't char foo[<expr>] (eg. dynamically sized automatic arrays) a GCCism? > > > > > > Oops, you're right. Updated patch attached. > -------------------------------------------------------------------------------- > ? Makefile > ? Umakefil.upp > ? vsrclocal.mak > ? vsrclocal.upp > ? vsrclocallib.mak > ? vsrclocallib.upp > ? vsrlocal.exp > Index: http_con.cpp > =================================================================== > RCS file: /cvsroot/client/viewsource/http_con.cpp,v > retrieving revision 1.1.1.1 > diff -u -r1.1.1.1 http_con.cpp > --- http_con.cpp 5 May 2004 14:43:31 -0000 1.1.1.1 > +++ http_con.cpp 12 May 2004 02:07:21 -0000 > @@ -571,11 +571,13 @@ > IHXBuffer* pBuf = NULL; > m_pClassFactory->CreateInstance(IID_IHXBuffer, (void**)&pBuf); > > - char pHeader[sizeof(m_pszHdr) + 10]; > + char* pHeader = new char[strlen(m_pszHdr) + 11]; > > - int iBodyStartLen = sizeof(m_pszBodyStart) + strlen(m_pUrl) - 3; // 1 for sizeof() 2 for %s > + int iBodyEndLen = strlen(m_pszBodyEnd); > + > + int iBodyStartLen = strlen(m_pszBodyStart) + strlen(m_pUrl) - 2; // 2 for %s > > - int iBodyLen = pBuffer->GetSize() + sizeof(m_pszBodyEnd) - 1; > + int iBodyLen = pBuffer->GetSize() + iBodyEndLen; > > sprintf(pHeader, m_pszHdr, iBodyLen + iBodyStartLen); > int iHeaderLen = strlen(pHeader); > @@ -597,10 +599,13 @@ > memcpy(buffer, pBuffer->GetBuffer(), pBuffer->GetSize()); > buffer += pBuffer->GetSize(); > > - memcpy(buffer, m_pszBodyEnd, sizeof(m_pszBodyEnd) - 1); > + memcpy(buffer, m_pszBodyEnd, iBodyEndLen); > WriteBuffer(pBuf); > } > HX_RELEASE(pBuf); > + > + delete [] pHeader; > + > return ret; > } > > -------------------------------------------------------------------------------- > _______________________________________________ > Common-dev mailing list > Common-dev at lists.helixcommunity.org > http://lists.helixcommunity.org/mailman/listinfo/common-dev >