r20828 by jghali -
scribus-commit
scribus-commit at lists.scribus.net
Sun Jan 31 00:25:41 UTC 2016
Author: jghali
Date: Sun Jan 31 00:25:40 2016
New Revision: 20828
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=20828
Log:
coverity #93107: resource leak
read_jpeg_marker return true only if data length is > 0. So remove the unneeded condition check to make coverity happy.
Modified:
trunk/Scribus/scribus/imagedataloaders/scimgdataloader_jpeg.cpp
Modified: trunk/Scribus/scribus/imagedataloaders/scimgdataloader_jpeg.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=20828&path=/trunk/Scribus/scribus/imagedataloaders/scimgdataloader_jpeg.cpp
==============================================================================
--- trunk/Scribus/scribus/imagedataloaders/scimgdataloader_jpeg.cpp (original)
+++ trunk/Scribus/scribus/imagedataloaders/scimgdataloader_jpeg.cpp Sun Jan 31 00:25:40 2016
@@ -78,8 +78,8 @@
jpeg_read_header(&cinfo, true);
//jpeg_start_decompress(&cinfo);
unsigned int EmbedLen = 0;
- unsigned char* EmbedBuffer;
- if (read_jpeg_marker(ICC_MARKER,&cinfo, &EmbedBuffer, &EmbedLen))
+ unsigned char* EmbedBuffer = 0;
+ if (read_jpeg_marker(ICC_MARKER, &cinfo, &EmbedBuffer, &EmbedLen))
{
QByteArray profArray = QByteArray((const char*) EmbedBuffer, EmbedLen);
ScColorProfile prof = ScCore->defaultEngine.openProfileFromMem(profArray);
@@ -229,7 +229,7 @@
m_imageInfoRecord.exifInfo.thumbnail = QImage();
unsigned int EmbedLen = 0;
unsigned char* EmbedBuffer;
- if (read_jpeg_marker(ICC_MARKER,&cinfo, &EmbedBuffer, &EmbedLen))
+ if (read_jpeg_marker(ICC_MARKER, &cinfo, &EmbedBuffer, &EmbedLen))
{
QByteArray profArray((const char*) EmbedBuffer, EmbedLen);
ScColorProfile prof = ScCore->defaultEngine.openProfileFromMem(profArray);
@@ -243,8 +243,7 @@
m_imageInfoRecord.isEmbedded = false;
m_imageInfoRecord.profileName = "";
}
- unsigned int PhotoshopLen = 0;
- unsigned char * PhotoshopBuffer;
+
if (cinfo.density_unit == 0)
{
xres = 72;
@@ -288,85 +287,85 @@
m_imageInfoRecord.colorspace = ColorSpaceGray;
m_imageInfoRecord.progressive = jpeg_has_multiple_scans(&cinfo);
- if (read_jpeg_marker(PHOTOSHOP_MARKER,&cinfo, &PhotoshopBuffer, &PhotoshopLen) )
- {
- if (PhotoshopLen != 0)
- {
- bool savEx = m_imageInfoRecord.exifDataValid;
- QByteArray arrayPhot(PhotoshopLen, ' ');
- arrayPhot = QByteArray::fromRawData((const char*)PhotoshopBuffer,PhotoshopLen);
- QDataStream strPhot(&arrayPhot,QIODevice::ReadOnly);
- strPhot.setByteOrder( QDataStream::BigEndian );
- PSDHeader fakeHeader;
- fakeHeader.width = cinfo.output_width;
- fakeHeader.height = cinfo.output_height;
+ unsigned int PhotoshopLen = 0;
+ unsigned char * PhotoshopBuffer = 0;
+ if (read_jpeg_marker(PHOTOSHOP_MARKER, &cinfo, &PhotoshopBuffer, &PhotoshopLen) )
+ {
+ bool savEx = m_imageInfoRecord.exifDataValid;
+ QByteArray arrayPhot(PhotoshopLen, ' ');
+ arrayPhot = QByteArray::fromRawData((const char*)PhotoshopBuffer,PhotoshopLen);
+ QDataStream strPhot(&arrayPhot,QIODevice::ReadOnly);
+ strPhot.setByteOrder( QDataStream::BigEndian );
+ PSDHeader fakeHeader;
+ fakeHeader.width = cinfo.output_width;
+ fakeHeader.height = cinfo.output_height;
+ if (cinfo.output_components == 4)
+ m_imageInfoRecord.colorspace = ColorSpaceCMYK;
+ else if (cinfo.output_components == 3)
+ m_imageInfoRecord.colorspace = ColorSpaceRGB;
+ else if (cinfo.output_components == 1)
+ m_imageInfoRecord.colorspace = ColorSpaceGray;
+ m_imageInfoRecord.progressive = jpeg_has_multiple_scans(&cinfo);
+ parseRessourceData(strPhot, fakeHeader, PhotoshopLen);
+ // Photoshop resolution is more accurate than jpeg header resolution
+ xres = m_imageInfoRecord.xres;
+ yres = m_imageInfoRecord.yres;
+ m_image.setDotsPerMeterX( int(100. * m_imageInfoRecord.xres / 2.54) );
+ m_image.setDotsPerMeterY( int(100. * m_imageInfoRecord.yres / 2.54) );
+ if( xres <= 1.0 || yres <= 1.0 || xres > 3000.0 || yres > 3000.0 )
+ {
+ xres = yres = 72.0;
+ m_imageInfoRecord.xres = qRound(xres);
+ m_imageInfoRecord.yres = qRound(yres);
+ m_image.setDotsPerMeterX(2834);
+ m_image.setDotsPerMeterY(2834);
+ QFileInfo qfi(fn);
+ m_message = QObject::tr("%1 may be corrupted : missing or wrong resolution tags").arg(qfi.fileName());
+ m_msgType = warningMsg;
+ }
+ if (m_imageInfoRecord.exifDataValid && !m_imageInfoRecord.exifInfo.thumbnail.isNull() && thumbnail)
+ {
+ m_image = QImage(m_imageInfoRecord.exifInfo.width, m_imageInfoRecord.exifInfo.height, QImage::Format_ARGB32 );
+ m_imageInfoRecord.exifInfo.width = cinfo.output_width;
+ m_imageInfoRecord.exifInfo.height = cinfo.output_height;
if (cinfo.output_components == 4)
- m_imageInfoRecord.colorspace = ColorSpaceCMYK;
- else if (cinfo.output_components == 3)
- m_imageInfoRecord.colorspace = ColorSpaceRGB;
- else if (cinfo.output_components == 1)
- m_imageInfoRecord.colorspace = ColorSpaceGray;
- m_imageInfoRecord.progressive = jpeg_has_multiple_scans(&cinfo);
- parseRessourceData(strPhot, fakeHeader, PhotoshopLen);
- // Photoshop resolution is more accurate than jpeg header resolution
- xres = m_imageInfoRecord.xres;
- yres = m_imageInfoRecord.yres;
- m_image.setDotsPerMeterX( int(100. * m_imageInfoRecord.xres / 2.54) );
- m_image.setDotsPerMeterY( int(100. * m_imageInfoRecord.yres / 2.54) );
- if( xres <= 1.0 || yres <= 1.0 || xres > 3000.0 || yres > 3000.0 )
{
- xres = yres = 72.0;
- m_imageInfoRecord.xres = qRound(xres);
- m_imageInfoRecord.yres = qRound(yres);
- m_image.setDotsPerMeterX(2834);
- m_image.setDotsPerMeterY(2834);
- QFileInfo qfi(fn);
- m_message = QObject::tr("%1 may be corrupted : missing or wrong resolution tags").arg(qfi.fileName());
- m_msgType = warningMsg;
- }
- if (m_imageInfoRecord.exifDataValid && !m_imageInfoRecord.exifInfo.thumbnail.isNull() && thumbnail)
- {
- m_image = QImage(m_imageInfoRecord.exifInfo.width, m_imageInfoRecord.exifInfo.height, QImage::Format_ARGB32 );
- m_imageInfoRecord.exifInfo.width = cinfo.output_width;
- m_imageInfoRecord.exifInfo.height = cinfo.output_height;
- if (cinfo.output_components == 4)
+ QRgb *d;
+ QRgb *s;
+ unsigned char cc, cm, cy, ck;
+ for( int yit=0; yit < m_image.height(); ++yit )
{
- QRgb *d;
- QRgb *s;
- unsigned char cc, cm, cy, ck;
- for( int yit=0; yit < m_image.height(); ++yit )
+ d = (QRgb*)(m_image.scanLine( yit ));
+ s = (QRgb*)(m_imageInfoRecord.exifInfo.thumbnail.scanLine( yit ));
+ for(int xit=0; xit < m_image.width(); ++xit )
{
- d = (QRgb*)(m_image.scanLine( yit ));
- s = (QRgb*)(m_imageInfoRecord.exifInfo.thumbnail.scanLine( yit ));
- for(int xit=0; xit < m_image.width(); ++xit )
- {
- cc = 255 - qRed(*s);
- cm = 255 - qGreen(*s);
- cy = 255 - qBlue(*s);
- ck = qMin(qMin(cc, cm), cy);
- *d = qRgba(cc-ck,cm-ck,cy-ck,ck);
- s++;
- d++;
- }
+ cc = 255 - qRed(*s);
+ cm = 255 - qGreen(*s);
+ cy = 255 - qBlue(*s);
+ ck = qMin(qMin(cc, cm), cy);
+ *d = qRgba(cc-ck,cm-ck,cy-ck,ck);
+ s++;
+ d++;
}
}
- else
- m_image = m_imageInfoRecord.exifInfo.thumbnail.copy();
- m_pixelFormat = Format_BGRA_8;
- }
- m_imageInfoRecord.valid = (m_imageInfoRecord.PDSpathData.size())>0?true:false; // The only interest is vectormask
- arrayPhot.clear();
- free( PhotoshopBuffer );
- if (m_imageInfoRecord.exifDataValid && !m_imageInfoRecord.exifInfo.thumbnail.isNull() && thumbnail)
- {
- jpeg_destroy_decompress(&cinfo);
- fclose(infile);
- return true;
- }
- m_imageInfoRecord.exifInfo.thumbnail = QImage();
- m_imageInfoRecord.exifDataValid = savEx;
- fromPS = true;
- }
+ }
+ else
+ m_image = m_imageInfoRecord.exifInfo.thumbnail.copy();
+ m_pixelFormat = Format_BGRA_8;
+ }
+ m_imageInfoRecord.valid = (m_imageInfoRecord.PDSpathData.size())>0?true:false; // The only interest is vectormask
+ arrayPhot.clear();
+ free(PhotoshopBuffer );
+ PhotoshopBuffer = 0;
+ if (m_imageInfoRecord.exifDataValid && !m_imageInfoRecord.exifInfo.thumbnail.isNull() && thumbnail)
+ {
+ jpeg_destroy_decompress(&cinfo);
+ fclose(infile);
+ return true;
+ }
+ m_imageInfoRecord.exifInfo.thumbnail = QImage();
+ m_imageInfoRecord.exifDataValid = savEx;
+ fromPS = true;
}
if ( cinfo.output_components == 3 || cinfo.output_components == 4)
m_image = QImage( cinfo.output_width, cinfo.output_height, QImage::Format_ARGB32 );
More information about the scribus-commit
mailing list