Kaydet (Commit) 7225de6c authored tarafından Takeshi Abe's avatar Takeshi Abe

Avoid possible resource leaks by boost::scoped_array

Change-Id: Ibc90eba9f336b649a968f584f2b36139c847d348
üst ccf74f31
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <vcl/virdev.hxx> #include <vcl/virdev.hxx>
#include "sgffilt.hxx" #include "sgffilt.hxx"
#include "sgfbram.hxx" #include "sgfbram.hxx"
#include <boost/scoped_array.hpp>
SgfHeader::SgfHeader() SgfHeader::SgfHeader()
{ {
...@@ -209,7 +210,7 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&) ...@@ -209,7 +210,7 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
sal_uInt16 i,j,k; // column/row/plane counter sal_uInt16 i,j,k; // column/row/plane counter
sal_uInt16 a,b; // helper variables sal_uInt16 a,b; // helper variables
sal_uInt8 pl1 = 0; // masks for the planes sal_uInt8 pl1 = 0; // masks for the planes
sal_uInt8* pBuf=NULL; // buffer for a pixel row boost::scoped_array<sal_uInt8> pBuf; // buffer for a pixel row
PcxExpand aPcx; PcxExpand aPcx;
sal_uLong nOfs; sal_uLong nOfs;
sal_uInt8 cRGB[4]; sal_uInt8 cRGB[4];
...@@ -233,11 +234,11 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&) ...@@ -233,11 +234,11 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
aBmpInfo.yDpmm=0; aBmpInfo.yDpmm=0;
aBmpInfo.ColUsed=0; aBmpInfo.ColUsed=0;
aBmpInfo.ColMust=0; aBmpInfo.ColMust=0;
pBuf=new sal_uInt8[nWdtOut]; pBuf.reset(new sal_uInt8[nWdtOut]);
if (!pBuf) return false; // error: no more memory available if (!pBuf) return false; // error: no more memory available
WriteBmpFileHeader( rOut, aBmpHead ); WriteBmpFileHeader( rOut, aBmpHead );
WriteBmpInfoHeader( rOut, aBmpInfo ); WriteBmpInfoHeader( rOut, aBmpInfo );
memset(pBuf,0,nWdtOut); // fill buffer with zeroes memset(pBuf.get(),0,nWdtOut); // fill buffer with zeroes
if (nColors==2) if (nColors==2)
{ {
...@@ -246,14 +247,14 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&) ...@@ -246,14 +247,14 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
WriteRGBQuad( rOut, RGBQuad(0xFF,0xFF,0xFF) ); // white WriteRGBQuad( rOut, RGBQuad(0xFF,0xFF,0xFF) ); // white
nOfs=rOut.Tell(); nOfs=rOut.Tell();
for (j=0;j<rHead.Ysize;j++) for (j=0;j<rHead.Ysize;j++)
rOut.Write((char*)pBuf,nWdtOut); // fill file with zeroes rOut.Write((char*)pBuf.get(),nWdtOut); // fill file with zeroes
for (j=0;j<rHead.Ysize;j++) { for (j=0;j<rHead.Ysize;j++) {
for(i=0;i<nWdtInp;i++) { for(i=0;i<nWdtInp;i++) {
pBuf[i]=aPcx.GetByte(rInp); pBuf[i]=aPcx.GetByte(rInp);
} }
for(i=nWdtInp;i<nWdtOut;i++) pBuf[i]=0; // up to 3 bytes for(i=nWdtInp;i<nWdtOut;i++) pBuf[i]=0; // up to 3 bytes
rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards
rOut.Write((char*)pBuf,nWdtOut); rOut.Write((char*)pBuf.get(),nWdtOut);
} }
} else if (nColors==16) { } else if (nColors==16) {
sal_uInt8 pl2= 0; // planes' masks sal_uInt8 pl2= 0; // planes' masks
...@@ -277,9 +278,9 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&) ...@@ -277,9 +278,9 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
nOfs=rOut.Tell(); nOfs=rOut.Tell();
for (j=0;j<rHead.Ysize;j++) for (j=0;j<rHead.Ysize;j++)
rOut.Write((char*)pBuf,nWdtOut); // fill file with zeroes rOut.Write((char*)pBuf.get(),nWdtOut); // fill file with zeroes
for (j=0;j<rHead.Ysize;j++) { for (j=0;j<rHead.Ysize;j++) {
memset(pBuf,0,nWdtOut); memset(pBuf.get(),0,nWdtOut);
for(k=0;k<4;k++) { for(k=0;k<4;k++) {
if (k==0) { if (k==0) {
pl1=0x10; pl2=0x01; pl1=0x10; pl2=0x01;
...@@ -301,7 +302,7 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&) ...@@ -301,7 +302,7 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
} }
for(i=nWdtInp*4;i<nWdtOut;i++) pBuf[i]=0; // up to 3 bytes for(i=nWdtInp*4;i<nWdtOut;i++) pBuf[i]=0; // up to 3 bytes
rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards
rOut.Write((char*)pBuf,nWdtOut); rOut.Write((char*)pBuf.get(),nWdtOut);
} }
} else if (nColors==256) { } else if (nColors==256) {
cRGB[3]=0; // fourth palette entry for BMP cRGB[3]=0; // fourth palette entry for BMP
...@@ -315,16 +316,15 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&) ...@@ -315,16 +316,15 @@ bool SgfFilterBMap(SvStream& rInp, SvStream& rOut, SgfHeader& rHead, SgfEntry&)
nOfs=rOut.Tell(); nOfs=rOut.Tell();
for (j=0;j<rHead.Ysize;j++) for (j=0;j<rHead.Ysize;j++)
rOut.Write((char*)pBuf,nWdtOut); // fill file with zeroes rOut.Write((char*)pBuf.get(),nWdtOut); // fill file with zeroes
for (j=0;j<rHead.Ysize;j++) { for (j=0;j<rHead.Ysize;j++) {
for(i=0;i<rHead.Xsize;i++) for(i=0;i<rHead.Xsize;i++)
pBuf[i]=aPcx.GetByte(rInp); pBuf[i]=aPcx.GetByte(rInp);
for(i=rHead.Xsize;i<nWdtOut;i++) pBuf[i]=0; // up to 3 bytes for(i=rHead.Xsize;i<nWdtOut;i++) pBuf[i]=0; // up to 3 bytes
rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards rOut.Seek(nOfs+((sal_uLong)rHead.Ysize-j-1L)*(sal_uLong)nWdtOut); // write backwards
rOut.Write((char*)pBuf,nWdtOut); rOut.Write((char*)pBuf.get(),nWdtOut);
} }
} }
delete[] pBuf;
return true; return true;
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <tools/poly.hxx> #include <tools/poly.hxx>
#include <boost/scoped_array.hpp>
extern "C" { extern "C" {
...@@ -418,17 +419,17 @@ sal_uInt16 NaturalSpline(sal_uInt16 n, double* x, double* y, ...@@ -418,17 +419,17 @@ sal_uInt16 NaturalSpline(sal_uInt16 n, double* x, double* y,
double* b, double* c, double* d) double* b, double* c, double* d)
{ {
sal_uInt16 i; sal_uInt16 i;
double* a; boost::scoped_array<double> a;
double* h; boost::scoped_array<double> h;
sal_uInt16 error; sal_uInt16 error;
if (n<2) return 1; if (n<2) return 1;
if ( (MargCond & ~3) ) return 2; if ( (MargCond & ~3) ) return 2;
a=new double[n+1]; a.reset(new double[n+1]);
h=new double[n+1]; h.reset(new double[n+1]);
for (i=0;i<n;i++) { for (i=0;i<n;i++) {
h[i]=x[i+1]-x[i]; h[i]=x[i+1]-x[i];
if (h[i]<=0.0) { delete[] a; delete[] h; return 1; } if (h[i]<=0.0) return 1;
} }
for (i=0;i<n-1;i++) { for (i=0;i<n-1;i++) {
a[i]=3.0*((y[i+2]-y[i+1])/h[i+1]-(y[i+1]-y[i])/h[i]); a[i]=3.0*((y[i+2]-y[i+1])/h[i+1]-(y[i+1]-y[i])/h[i]);
...@@ -470,8 +471,8 @@ sal_uInt16 NaturalSpline(sal_uInt16 n, double* x, double* y, ...@@ -470,8 +471,8 @@ sal_uInt16 NaturalSpline(sal_uInt16 n, double* x, double* y,
if (n==2) { if (n==2) {
c[1]=a[0]/d[0]; c[1]=a[0]/d[0];
} else { } else {
error=TriDiagGS(false,n-1,b,d,c,a); error=TriDiagGS(false,n-1,b,d,c,a.get());
if (error!=0) { delete[] a; delete[] h; return error+2; } if (error!=0) return error+2;
for (i=0;i<n-1;i++) c[i+1]=a[i]; for (i=0;i<n-1;i++) c[i+1]=a[i];
} }
switch (MargCond) { switch (MargCond) {
...@@ -503,8 +504,6 @@ sal_uInt16 NaturalSpline(sal_uInt16 n, double* x, double* y, ...@@ -503,8 +504,6 @@ sal_uInt16 NaturalSpline(sal_uInt16 n, double* x, double* y,
b[i]=(y[i+1]-y[i])/h[i]-h[i]*(c[i+1]+2.0*c[i])/3.0; b[i]=(y[i+1]-y[i])/h[i]-h[i]*(c[i+1]+2.0*c[i])/3.0;
d[i]=(c[i+1]-c[i])/(3.0*h[i]); d[i]=(c[i+1]-c[i])/(3.0*h[i]);
} }
delete[] a;
delete[] h;
return 0; return 0;
} }
...@@ -525,18 +524,18 @@ sal_uInt16 PeriodicSpline(sal_uInt16 n, double* x, double* y, ...@@ -525,18 +524,18 @@ sal_uInt16 PeriodicSpline(sal_uInt16 n, double* x, double* y,
sal_uInt16 Error; sal_uInt16 Error;
sal_uInt16 i,im1,nm1; //integer sal_uInt16 i,im1,nm1; //integer
double hr,hl; double hr,hl;
double* a; boost::scoped_array<double> a;
double* lowrow; boost::scoped_array<double> lowrow;
double* ricol; boost::scoped_array<double> ricol;
if (n<2) return 4; if (n<2) return 4;
nm1=n-1; nm1=n-1;
for (i=0;i<=nm1;i++) if (x[i+1]<=x[i]) return 2; // should be strictly monotonically decreasing! for (i=0;i<=nm1;i++) if (x[i+1]<=x[i]) return 2; // should be strictly monotonically decreasing!
if (y[n]!=y[0]) return 3; // begin and end should be equal! if (y[n]!=y[0]) return 3; // begin and end should be equal!
a =new double[n+1]; a.reset(new double[n+1]);
lowrow=new double[n+1]; lowrow.reset(new double[n+1]);
ricol =new double[n+1]; ricol.reset(new double[n+1]);
if (n==2) { if (n==2) {
c[1]=3.0*((y[2]-y[1])/(x[2]-x[1])); c[1]=3.0*((y[2]-y[1])/(x[2]-x[1]));
...@@ -560,12 +559,9 @@ sal_uInt16 PeriodicSpline(sal_uInt16 n, double* x, double* y, ...@@ -560,12 +559,9 @@ sal_uInt16 PeriodicSpline(sal_uInt16 n, double* x, double* y,
lowrow[0]=hr; lowrow[0]=hr;
ricol[0]=hr; ricol[0]=hr;
a[nm1]=3.0*((y[1]-y[0])/hr-(y[n]-y[nm1])/hl); a[nm1]=3.0*((y[1]-y[0])/hr-(y[n]-y[nm1])/hl);
Error=ZyklTriDiagGS(false,n,b,d,c,lowrow,ricol,a); Error=ZyklTriDiagGS(false,n,b,d,c,lowrow.get(),ricol.get(),a.get());
if ( Error != 0 ) if ( Error != 0 )
{ {
delete[] a;
delete[] lowrow;
delete[] ricol;
return(Error+4); return(Error+4);
} }
for (i=0;i<=nm1;i++) c[i+1]=a[i]; for (i=0;i<=nm1;i++) c[i+1]=a[i];
...@@ -577,9 +573,6 @@ sal_uInt16 PeriodicSpline(sal_uInt16 n, double* x, double* y, ...@@ -577,9 +573,6 @@ sal_uInt16 PeriodicSpline(sal_uInt16 n, double* x, double* y,
b[i]=b[i]-hl*(c[i+1]+2.0*c[i])/3.0; b[i]=b[i]-hl*(c[i+1]+2.0*c[i])/3.0;
d[i]=(c[i+1]-c[i])/hl/3.0; d[i]=(c[i+1]-c[i])/hl/3.0;
} }
delete[] a;
delete[] lowrow;
delete[] ricol;
return 0; return 0;
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "sgffilt.hxx" #include "sgffilt.hxx"
#include "sgfbram.hxx" #include "sgfbram.hxx"
#include "sgvmain.hxx" #include "sgvmain.hxx"
#include <boost/scoped_array.hpp>
extern SgfFontLst* pSgfFonts; extern SgfFontLst* pSgfFonts;
...@@ -906,8 +907,8 @@ void TextType::Draw(OutputDevice& rOut) ...@@ -906,8 +907,8 @@ void TextType::Draw(OutputDevice& rOut)
bool Ende = false; bool Ende = false;
sal_uInt16 lc; sal_uInt16 lc;
bool TextFit; bool TextFit;
short* xLine; boost::scoped_array<short> xLine;
UCHAR* cLine; // Buffer for FormatLine boost::scoped_array<UCHAR> cLine; // Buffer for FormatLine
sal_uInt16 FitXMul; sal_uInt16 FitXMul;
sal_uInt16 FitXDiv; sal_uInt16 FitXDiv;
sal_uInt16 FitYMul; sal_uInt16 FitYMul;
...@@ -916,8 +917,8 @@ void TextType::Draw(OutputDevice& rOut) ...@@ -916,8 +917,8 @@ void TextType::Draw(OutputDevice& rOut)
UCHAR* Buf=Buffer; // pointer to the letters UCHAR* Buf=Buffer; // pointer to the letters
pSgfFonts->ReadList(); pSgfFonts->ReadList();
xLine=new short[ChrXPosArrSize]; xLine.reset(new short[ChrXPosArrSize]);
cLine=new UCHAR[CharLineSize]; cLine.reset(new UCHAR[CharLineSize]);
TextFit=(Flags & TextFitBits)!=0; TextFit=(Flags & TextFitBits)!=0;
bool LineFit=((Flags & TextFitZBit)!=0); // FitSize.x=0? or flags -> strech each line bool LineFit=((Flags & TextFitZBit)!=0); // FitSize.x=0? or flags -> strech each line
...@@ -951,7 +952,7 @@ void TextType::Draw(OutputDevice& rOut) ...@@ -951,7 +952,7 @@ void TextType::Draw(OutputDevice& rOut)
do { do {
T2=T1; Index2=Index1; T2=T1; Index2=Index1;
FormatLine(Buf,Index2,T,T2,xSize,xSAdj,xLine,l,sn,cs,cLine,LineFit); FormatLine(Buf,Index2,T,T2,xSize,xSAdj,xLine.get(),l,sn,cs,cLine.get(),LineFit);
Fehler=(Index2==Index1); Fehler=(Index2==Index1);
if (!Fehler) { if (!Fehler) {
lc=GetLineFeed(Buf,Index1,T,T1,l,LF,MaxGrad); lc=GetLineFeed(Buf,Index1,T,T1,l,LF,MaxGrad);
...@@ -996,8 +997,6 @@ void TextType::Draw(OutputDevice& rOut) ...@@ -996,8 +997,6 @@ void TextType::Draw(OutputDevice& rOut)
} // if ObjMin.y+yPos<=Obj_Max.y } // if ObjMin.y+yPos<=Obj_Max.y
} // if !Fehler } // if !Fehler
} while (c!=TextEnd && !Ende && !Fehler); } while (c!=TextEnd && !Ende && !Fehler);
delete[] cLine;
delete[] xLine;
} }
// End of DrawText.Pas // End of DrawText.Pas
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <basegfx/polygon/b2dpolypolygon.hxx> #include <basegfx/polygon/b2dpolypolygon.hxx>
#include <vcl/lineinfo.hxx> #include <vcl/lineinfo.hxx>
#include <vcl/dibtools.hxx> #include <vcl/dibtools.hxx>
#include <boost/scoped_array.hpp>
#define WIN_EMR_POLYGON 3 #define WIN_EMR_POLYGON 3
#define WIN_EMR_POLYLINE 4 #define WIN_EMR_POLYLINE 4
...@@ -878,21 +879,20 @@ void EMFWriter::ImplWriteTextRecord( const Point& rPos, const OUString rText, co ...@@ -878,21 +879,20 @@ void EMFWriter::ImplWriteTextRecord( const Point& rPos, const OUString rText, co
if( nLen ) if( nLen )
{ {
sal_uInt32 nNormWidth; sal_uInt32 nNormWidth;
sal_Int32* pOwnArray; boost::scoped_array<sal_Int32> pOwnArray;
sal_Int32* pDX; sal_Int32* pDX;
// get text sizes // get text sizes
if( pDXArray ) if( pDXArray )
{ {
pOwnArray = NULL;
nNormWidth = maVDev.GetTextWidth( rText ); nNormWidth = maVDev.GetTextWidth( rText );
pDX = (sal_Int32*) pDXArray; pDX = (sal_Int32*) pDXArray;
} }
else else
{ {
pOwnArray = new sal_Int32[ nLen ]; pOwnArray.reset(new sal_Int32[ nLen ]);
nNormWidth = maVDev.GetTextArray( rText, pOwnArray ); nNormWidth = maVDev.GetTextArray( rText, pOwnArray.get() );
pDX = pOwnArray; pDX = pOwnArray.get();
} }
if( nLen > 1 ) if( nLen > 1 )
...@@ -939,7 +939,6 @@ void EMFWriter::ImplWriteTextRecord( const Point& rPos, const OUString rText, co ...@@ -939,7 +939,6 @@ void EMFWriter::ImplWriteTextRecord( const Point& rPos, const OUString rText, co
} }
ImplEndRecord(); ImplEndRecord();
delete[] pOwnArray;
} }
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <basegfx/matrix/b2dhommatrix.hxx> #include <basegfx/matrix/b2dhommatrix.hxx>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <vcl/dibtools.hxx> #include <vcl/dibtools.hxx>
#include <boost/scoped_array.hpp>
using namespace std; using namespace std;
...@@ -373,7 +374,7 @@ void EnhWMFReader::ReadAndDrawPolyLine() ...@@ -373,7 +374,7 @@ void EnhWMFReader::ReadAndDrawPolyLine()
( static_cast< sal_uInt32 >( nPoly ) * sizeof(sal_uInt16) ) <= ( nEndPos - pWMF->Tell() ) ( static_cast< sal_uInt32 >( nPoly ) * sizeof(sal_uInt16) ) <= ( nEndPos - pWMF->Tell() )
) )
{ {
sal_uInt16* pnPoints = new sal_uInt16[ nPoly ]; boost::scoped_array<sal_uInt16> pnPoints(new sal_uInt16[ nPoly ]);
for ( i = 0; i < nPoly && pWMF->good(); i++ ) for ( i = 0; i < nPoly && pWMF->good(); i++ )
{ {
pWMF->ReadUInt32( nPoints ); pWMF->ReadUInt32( nPoints );
...@@ -385,7 +386,6 @@ void EnhWMFReader::ReadAndDrawPolyLine() ...@@ -385,7 +386,6 @@ void EnhWMFReader::ReadAndDrawPolyLine()
Polygon aPolygon = ReadPolygon<T>(0, pnPoints[i]); Polygon aPolygon = ReadPolygon<T>(0, pnPoints[i]);
pOut->DrawPolyLine( aPolygon, false, bRecordPath ); pOut->DrawPolyLine( aPolygon, false, bRecordPath );
} }
delete[] pnPoints;
} }
} }
...@@ -418,7 +418,7 @@ void EnhWMFReader::ReadAndDrawPolyPolygon() ...@@ -418,7 +418,7 @@ void EnhWMFReader::ReadAndDrawPolyPolygon()
( ( nPoly * sizeof( sal_uInt16 ) ) <= ( nEndPos - pWMF->Tell() ) )) ( ( nPoly * sizeof( sal_uInt16 ) ) <= ( nEndPos - pWMF->Tell() ) ))
{ {
// Get number of points in each polygon // Get number of points in each polygon
sal_uInt16 * pnPoints = new sal_uInt16[ nPoly ]; boost::scoped_array<sal_uInt16> pnPoints(new sal_uInt16[ nPoly ]);
for (sal_uInt32 i = 0; i < nPoly && pWMF->good(); ++i) for (sal_uInt32 i = 0; i < nPoly && pWMF->good(); ++i)
{ {
sal_uInt32 nPoints(0); sal_uInt32 nPoints(0);
...@@ -432,7 +432,7 @@ void EnhWMFReader::ReadAndDrawPolyPolygon() ...@@ -432,7 +432,7 @@ void EnhWMFReader::ReadAndDrawPolyPolygon()
for (sal_uInt32 i = 0; i < nPoly && pWMF->good(); ++i) for (sal_uInt32 i = 0; i < nPoly && pWMF->good(); ++i)
{ {
const sal_uInt16 nPointCount(pnPoints[i]); const sal_uInt16 nPointCount(pnPoints[i]);
Point* pPtAry = new Point[nPointCount]; boost::scoped_array<Point> pPtAry(new Point[nPointCount]);
for (sal_uInt16 j = 0; j < nPointCount && pWMF->good(); ++j) for (sal_uInt16 j = 0; j < nPointCount && pWMF->good(); ++j)
{ {
T nX(0), nY(0); T nX(0), nY(0);
...@@ -441,13 +441,11 @@ void EnhWMFReader::ReadAndDrawPolyPolygon() ...@@ -441,13 +441,11 @@ void EnhWMFReader::ReadAndDrawPolyPolygon()
++nReadPoints; ++nReadPoints;
} }
aPolyPoly.Insert(Polygon(nPointCount, pPtAry)); aPolyPoly.Insert(Polygon(nPointCount, pPtAry.get()));
delete[] pPtAry;
} }
pOut->DrawPolyPolygon( aPolyPoly, bRecordPath ); pOut->DrawPolyPolygon( aPolyPoly, bRecordPath );
} }
delete[] pnPoints;
OSL_ENSURE(nReadPoints == nGesPoints, "The number Points processed from EMR_POLYPOLYGON is unequal imported number (!)"); OSL_ENSURE(nReadPoints == nGesPoints, "The number Points processed from EMR_POLYPOLYGON is unequal imported number (!)");
...@@ -1284,10 +1282,10 @@ bool EnhWMFReader::ReadEnhWMF() ...@@ -1284,10 +1282,10 @@ bool EnhWMFReader::ReadEnhWMF()
{ {
if ( nLen <= static_cast<sal_Int32>( nEndPos - pWMF->Tell() ) ) if ( nLen <= static_cast<sal_Int32>( nEndPos - pWMF->Tell() ) )
{ {
sal_Char* pBuf = new sal_Char[ nLen ]; boost::scoped_array<sal_Char> pBuf(new sal_Char[ nLen ]);
pWMF->Read( pBuf, nLen ); pWMF->Read( pBuf.get(), nLen );
aText = OUString( pBuf, (sal_uInt16)nLen, pOut->GetCharSet() ); aText = OUString( pBuf.get(), (sal_uInt16)nLen, pOut->GetCharSet() );
delete[] pBuf; pBuf.reset();
if ( aText.getLength() != nLen ) if ( aText.getLength() != nLen )
{ {
...@@ -1310,19 +1308,18 @@ bool EnhWMFReader::ReadEnhWMF() ...@@ -1310,19 +1308,18 @@ bool EnhWMFReader::ReadEnhWMF()
{ {
if ( ( nLen * sizeof(sal_Unicode) ) <= ( nEndPos - pWMF->Tell() ) ) if ( ( nLen * sizeof(sal_Unicode) ) <= ( nEndPos - pWMF->Tell() ) )
{ {
sal_Unicode* pBuf = new sal_Unicode[ nLen ]; boost::scoped_array<sal_Unicode> pBuf(new sal_Unicode[ nLen ]);
pWMF->Read( pBuf, nLen << 1 ); pWMF->Read( pBuf.get(), nLen << 1 );
#ifdef OSL_BIGENDIAN #ifdef OSL_BIGENDIAN
sal_Char nTmp, *pTmp = (sal_Char*)( pBuf + nLen ); sal_Char nTmp, *pTmp = (sal_Char*)( pBuf.get() + nLen );
while ( pTmp-- != (sal_Char*)pBuf ) while ( pTmp-- != (sal_Char*)pBuf.get() )
{ {
nTmp = *pTmp--; nTmp = *pTmp--;
pTmp[ 1 ] = *pTmp; pTmp[ 1 ] = *pTmp;
*pTmp = nTmp; *pTmp = nTmp;
} }
#endif #endif
aText = OUString(pBuf, nLen); aText = OUString(pBuf.get(), nLen);
delete[] pBuf;
} }
} }
pOut->DrawText( aPos, aText, pDX, bRecordPath, nGfxMode ); pOut->DrawText( aPos, aText, pDX, bRecordPath, nGfxMode );
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <osl/endian.h> #include <osl/endian.h>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/dibtools.hxx> #include <vcl/dibtools.hxx>
#include <boost/scoped_array.hpp>
// MS Windows defines // MS Windows defines
...@@ -442,10 +443,10 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) ...@@ -442,10 +443,10 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
pWMF->ReadUInt16( nLength ); pWMF->ReadUInt16( nLength );
if ( nLength ) if ( nLength )
{ {
char* pChar = new char[ ( nLength + 1 ) &~ 1 ]; boost::scoped_array<char> pChar(new char[ ( nLength + 1 ) &~ 1 ]);
pWMF->Read( pChar, ( nLength + 1 ) &~ 1 ); pWMF->Read( pChar.get(), ( nLength + 1 ) &~ 1 );
OUString aText( pChar, nLength, pOut->GetCharSet() ); OUString aText( pChar.get(), nLength, pOut->GetCharSet() );
delete[] pChar; pChar.reset();
Point aPosition( ReadYX() ); Point aPosition( ReadYX() );
pOut->DrawText( aPosition, aText ); pOut->DrawText( aPosition, aText );
} }
...@@ -458,7 +459,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) ...@@ -458,7 +459,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
sal_Int32 nRecordPos, nRecordSize = 0, nOriginalTextLen, nNewTextLen; sal_Int32 nRecordPos, nRecordSize = 0, nOriginalTextLen, nNewTextLen;
Point aPosition; Point aPosition;
Rectangle aRect; Rectangle aRect;
sal_Int32* pDXAry = NULL; boost::scoped_array<sal_Int32> pDXAry;
pWMF->SeekRel(-6); pWMF->SeekRel(-6);
nRecordPos = pWMF->Tell(); nRecordPos = pWMF->Tell();
...@@ -483,11 +484,11 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) ...@@ -483,11 +484,11 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
const Point aPt2( ReadPoint() ); const Point aPt2( ReadPoint() );
aRect = Rectangle( aPt1, aPt2 ); aRect = Rectangle( aPt1, aPt2 );
} }
char* pChar = new char[ ( nOriginalTextLen + 1 ) &~ 1 ]; boost::scoped_array<char> pChar(new char[ ( nOriginalTextLen + 1 ) &~ 1 ]);
pWMF->Read( pChar, ( nOriginalTextLen + 1 ) &~ 1 ); pWMF->Read( pChar.get(), ( nOriginalTextLen + 1 ) &~ 1 );
OUString aText( pChar, (sal_uInt16)nOriginalTextLen, pOut->GetCharSet() );// after this conversion the text may contain OUString aText( pChar.get(), (sal_uInt16)nOriginalTextLen, pOut->GetCharSet() );// after this conversion the text may contain
nNewTextLen = aText.getLength(); // less character (japanese version), so the nNewTextLen = aText.getLength(); // less character (japanese version), so the
delete[] pChar; // dxAry will not fit pChar.reset(); // dxAry will not fit
if ( nNewTextLen ) if ( nNewTextLen )
{ {
...@@ -500,7 +501,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) ...@@ -500,7 +501,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
{ {
sal_Int16 nDx = 0, nDxTmp = 0; sal_Int16 nDx = 0, nDxTmp = 0;
sal_uInt16 i; //needed just outside the for sal_uInt16 i; //needed just outside the for
pDXAry = new sal_Int32[ nNewTextLen ]; pDXAry.reset(new sal_Int32[ nNewTextLen ]);
for (i = 0; i < nNewTextLen; i++ ) for (i = 0; i < nNewTextLen; i++ )
{ {
if ( pWMF->Tell() >= nMaxStreamPos ) if ( pWMF->Tell() >= nMaxStreamPos )
...@@ -528,13 +529,11 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) ...@@ -528,13 +529,11 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
bUseDXAry = true; bUseDXAry = true;
} }
if ( pDXAry && bUseDXAry ) if ( pDXAry && bUseDXAry )
pOut->DrawText( aPosition, aText, pDXAry ); pOut->DrawText( aPosition, aText, pDXAry.get() );
else else
pOut->DrawText( aPosition, aText ); pOut->DrawText( aPosition, aText );
} }
} }
delete[] pDXAry;
} }
break; break;
...@@ -939,7 +938,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) ...@@ -939,7 +938,7 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
#else #else
sal_uInt32 nCheckSum = rtl_crc32( 0, &nEsc, 4 ); sal_uInt32 nCheckSum = rtl_crc32( 0, &nEsc, 4 );
#endif #endif
sal_Int8* pData = NULL; boost::scoped_array<sal_Int8> pData;
if ( ( static_cast< sal_uInt64 >( nEscLen ) + pWMF->Tell() ) > nMetaRecEndPos ) if ( ( static_cast< sal_uInt64 >( nEscLen ) + pWMF->Tell() ) > nMetaRecEndPos )
{ {
...@@ -948,9 +947,9 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) ...@@ -948,9 +947,9 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
} }
if ( nEscLen > 0 ) if ( nEscLen > 0 )
{ {
pData = new sal_Int8[ nEscLen ]; pData.reset(new sal_Int8[ nEscLen ]);
pWMF->Read( pData, nEscLen ); pWMF->Read( pData.get(), nEscLen );
nCheckSum = rtl_crc32( nCheckSum, pData, nEscLen ); nCheckSum = rtl_crc32( nCheckSum, pData.get(), nEscLen );
} }
if ( nCheck == nCheckSum ) if ( nCheck == nCheckSum )
{ {
...@@ -964,9 +963,9 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) ...@@ -964,9 +963,9 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
Point aPt; Point aPt;
OUString aString; OUString aString;
sal_uInt32 nStringLen, nDXCount; sal_uInt32 nStringLen, nDXCount;
sal_Int32* pDXAry = NULL; boost::scoped_array<sal_Int32> pDXAry;
SvMemoryStream aMemoryStream( nEscLen ); SvMemoryStream aMemoryStream( nEscLen );
aMemoryStream.Write( pData, nEscLen ); aMemoryStream.Write( pData.get(), nEscLen );
aMemoryStream.Seek( STREAM_SEEK_TO_BEGIN ); aMemoryStream.Seek( STREAM_SEEK_TO_BEGIN );
//#fdo39428 SvStream no longer supports operator>>(long&) //#fdo39428 SvStream no longer supports operator>>(long&)
sal_Int32 nTmpX(0), nTmpY(0); sal_Int32 nTmpX(0), nTmpY(0);
...@@ -984,19 +983,17 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) ...@@ -984,19 +983,17 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
if ( ( static_cast< sal_uInt64 >( nDXCount ) * sizeof( sal_Int32 ) ) >= ( nEscLen - aMemoryStream.Tell() ) ) if ( ( static_cast< sal_uInt64 >( nDXCount ) * sizeof( sal_Int32 ) ) >= ( nEscLen - aMemoryStream.Tell() ) )
nDXCount = 0; nDXCount = 0;
if ( nDXCount ) if ( nDXCount )
pDXAry = new sal_Int32[ nDXCount ]; pDXAry.reset(new sal_Int32[ nDXCount ]);
for (sal_uInt32 i = 0; i < nDXCount; i++ ) for (sal_uInt32 i = 0; i < nDXCount; i++ )
aMemoryStream.ReadInt32( pDXAry[ i ] ); aMemoryStream.ReadInt32( pDXAry[ i ] );
aMemoryStream.ReadUInt32( nSkipActions ); aMemoryStream.ReadUInt32( nSkipActions );
pOut->DrawText( aPt, aString, pDXAry ); pOut->DrawText( aPt, aString, pDXAry.get() );
delete[] pDXAry;
} }
} }
} }
break; break;
} }
} }
delete[] pData;
} }
} }
} }
...@@ -1037,11 +1034,10 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc ) ...@@ -1037,11 +1034,10 @@ void WMFReader::ReadRecordParams( sal_uInt16 nFunc )
if( pEMFStream ) if( pEMFStream )
{ {
sal_Int8* pBuf = new sal_Int8[ nCurRecSize ]; boost::scoped_array<sal_Int8> pBuf(new sal_Int8[ nCurRecSize ]);
sal_uInt32 nCount = pWMF->Read( pBuf, nCurRecSize ); sal_uInt32 nCount = pWMF->Read( pBuf.get(), nCurRecSize );
if( nCount == nCurRecSize ) if( nCount == nCurRecSize )
pEMFStream->Write( pBuf, nCount ); pEMFStream->Write( pBuf.get(), nCount );
delete[] pBuf;
} }
} }
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <vcl/metric.hxx> #include <vcl/metric.hxx>
#include <basegfx/polygon/b2dpolygon.hxx> #include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx> #include <basegfx/polygon/b2dpolypolygon.hxx>
#include <boost/scoped_array.hpp>
// MS Windows defines // MS Windows defines
...@@ -545,7 +546,7 @@ void WMFWriter::TrueExtTextOut( const Point & rPoint, const OUString & rString, ...@@ -545,7 +546,7 @@ void WMFWriter::TrueExtTextOut( const Point & rPoint, const OUString & rString,
pWMF->WriteUChar( (sal_uInt8)0 ); pWMF->WriteUChar( (sal_uInt8)0 );
sal_Int32 nOriginalTextLen = rString.getLength(); sal_Int32 nOriginalTextLen = rString.getLength();
sal_Int16* pConvertedDXAry = new sal_Int16[ nOriginalTextLen ]; boost::scoped_array<sal_Int16> pConvertedDXAry(new sal_Int16[ nOriginalTextLen ]);
sal_Int32 j = 0; sal_Int32 j = 0;
pConvertedDXAry[ j++ ] = (sal_Int16)ScaleWidth( pDXAry[ 0 ] ); pConvertedDXAry[ j++ ] = (sal_Int16)ScaleWidth( pDXAry[ 0 ] );
for (sal_uInt16 i = 1; i < ( nOriginalTextLen - 1 ); ++i) for (sal_uInt16 i = 1; i < ( nOriginalTextLen - 1 ); ++i)
...@@ -565,7 +566,7 @@ void WMFWriter::TrueExtTextOut( const Point & rPoint, const OUString & rString, ...@@ -565,7 +566,7 @@ void WMFWriter::TrueExtTextOut( const Point & rPoint, const OUString & rString,
pWMF->WriteUInt16( (sal_uInt16)0 ); pWMF->WriteUInt16( (sal_uInt16)0 );
} }
} }
delete[] pConvertedDXAry; pConvertedDXAry.reset();
UpdateRecordHeader(); UpdateRecordHeader();
} }
...@@ -1198,17 +1199,16 @@ void WMFWriter::WriteRecords( const GDIMetaFile & rMTF ) ...@@ -1198,17 +1199,16 @@ void WMFWriter::WriteRecords( const GDIMetaFile & rMTF )
pVirDev->SetFont( aSrcFont ); pVirDev->SetFont( aSrcFont );
nLen = aTemp.getLength(); nLen = aTemp.getLength();
sal_Int32* pDXAry = nLen ? new sal_Int32[ nLen ] : NULL; boost::scoped_array<sal_Int32> pDXAry(nLen ? new sal_Int32[ nLen ] : NULL);
nNormSize = pVirDev->GetTextArray( aTemp, pDXAry ); nNormSize = pVirDev->GetTextArray( aTemp, pDXAry.get() );
for ( i = 0; i < ( nLen - 1 ); i++ ) for ( i = 0; i < ( nLen - 1 ); i++ )
pDXAry[ i ] = pDXAry[ i ] * (sal_Int32)pA->GetWidth() / nNormSize; pDXAry[ i ] = pDXAry[ i ] * (sal_Int32)pA->GetWidth() / nNormSize;
if ( ( nLen <= 1 ) || ( (sal_Int32)pA->GetWidth() == nNormSize ) ) if ( ( nLen <= 1 ) || ( (sal_Int32)pA->GetWidth() == nNormSize ) )
delete[] pDXAry, pDXAry = NULL; pDXAry.reset();
aSrcLineInfo = LineInfo(); aSrcLineInfo = LineInfo();
SetAllAttr(); SetAllAttr();
if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, pDXAry ) ) if ( !WMFRecord_Escape_Unicode( pA->GetPoint(), aTemp, pDXAry.get() ) )
WMFRecord_ExtTextOut( pA->GetPoint(), aTemp, pDXAry ); WMFRecord_ExtTextOut( pA->GetPoint(), aTemp, pDXAry.get() );
delete[] pDXAry;
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment