TGATranslator: Fix PVS 2332-2337, 2341-2346
* Use new(std::nothrow) so that NULL check for allocated memory makes sense. * Other new() without NULL check is replaced with new(std::nothrow). Change-Id: Ida53be936d14ce63b3bc60442408ec5044df5344 Reviewed-on: https://review.haiku-os.org/699 Reviewed-by: Adrien Destugues <[email protected]> Reviewed-by: Stephan Aßmus <[email protected]>
This commit is contained in:
committed by
Stephan Aßmus
parent
e0dbea8a60
commit
63757dbb24
@@ -122,7 +122,7 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...)
|
|||||||
{
|
{
|
||||||
BTranslator *ptranslator = NULL;
|
BTranslator *ptranslator = NULL;
|
||||||
if (!n)
|
if (!n)
|
||||||
ptranslator = new TGATranslator();
|
ptranslator = new(std::nothrow) TGATranslator();
|
||||||
|
|
||||||
return ptranslator;
|
return ptranslator;
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ make_nth_translator(int32 n, image_id you, uint32 flags, ...)
|
|||||||
// Returns:
|
// Returns:
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
TGATranslator::TGATranslator()
|
TGATranslator::TGATranslator()
|
||||||
: BaseTranslator(B_TRANSLATE("TGA images"),
|
: BaseTranslator(B_TRANSLATE("TGA images"),
|
||||||
B_TRANSLATE("TGA image translator"),
|
B_TRANSLATE("TGA image translator"),
|
||||||
TGA_TRANSLATOR_VERSION,
|
TGA_TRANSLATOR_VERSION,
|
||||||
sInputFormats, kNumInputFormats,
|
sInputFormats, kNumInputFormats,
|
||||||
@@ -394,34 +394,34 @@ identify_tga_header(BPositionIO *inSource, translator_info *outInfo,
|
|||||||
outInfo->capability = TGA_IN_CAPABILITY;
|
outInfo->capability = TGA_IN_CAPABILITY;
|
||||||
switch (fileheader.imagetype) {
|
switch (fileheader.imagetype) {
|
||||||
case TGA_NOCOMP_COLORMAP:
|
case TGA_NOCOMP_COLORMAP:
|
||||||
snprintf(outInfo->name, sizeof(outInfo->name),
|
snprintf(outInfo->name, sizeof(outInfo->name),
|
||||||
B_TRANSLATE("Targa image (%d bits colormap)"),
|
B_TRANSLATE("Targa image (%d bits colormap)"),
|
||||||
imagespec.depth);
|
imagespec.depth);
|
||||||
break;
|
break;
|
||||||
case TGA_NOCOMP_TRUECOLOR:
|
case TGA_NOCOMP_TRUECOLOR:
|
||||||
snprintf(outInfo->name, sizeof(outInfo->name),
|
snprintf(outInfo->name, sizeof(outInfo->name),
|
||||||
B_TRANSLATE("Targa image (%d bits truecolor)"),
|
B_TRANSLATE("Targa image (%d bits truecolor)"),
|
||||||
imagespec.depth);
|
imagespec.depth);
|
||||||
break;
|
break;
|
||||||
case TGA_RLE_COLORMAP:
|
case TGA_RLE_COLORMAP:
|
||||||
snprintf(outInfo->name, sizeof(outInfo->name),
|
snprintf(outInfo->name, sizeof(outInfo->name),
|
||||||
B_TRANSLATE("Targa image (%d bits RLE colormap)"),
|
B_TRANSLATE("Targa image (%d bits RLE colormap)"),
|
||||||
imagespec.depth);
|
imagespec.depth);
|
||||||
break;
|
break;
|
||||||
case TGA_RLE_TRUECOLOR:
|
case TGA_RLE_TRUECOLOR:
|
||||||
snprintf(outInfo->name, sizeof(outInfo->name),
|
snprintf(outInfo->name, sizeof(outInfo->name),
|
||||||
B_TRANSLATE("Targa image (%d bits RLE truecolor)"),
|
B_TRANSLATE("Targa image (%d bits RLE truecolor)"),
|
||||||
imagespec.depth);
|
imagespec.depth);
|
||||||
break;
|
break;
|
||||||
case TGA_RLE_BW:
|
case TGA_RLE_BW:
|
||||||
snprintf(outInfo->name, sizeof(outInfo->name),
|
snprintf(outInfo->name, sizeof(outInfo->name),
|
||||||
B_TRANSLATE("Targa image (%d bits RLE gray)"),
|
B_TRANSLATE("Targa image (%d bits RLE gray)"),
|
||||||
imagespec.depth);
|
imagespec.depth);
|
||||||
break;
|
break;
|
||||||
case TGA_NOCOMP_BW:
|
case TGA_NOCOMP_BW:
|
||||||
default:
|
default:
|
||||||
snprintf(outInfo->name, sizeof(outInfo->name),
|
snprintf(outInfo->name, sizeof(outInfo->name),
|
||||||
B_TRANSLATE("Targa image (%d bits gray)"),
|
B_TRANSLATE("Targa image (%d bits gray)"),
|
||||||
imagespec.depth);
|
imagespec.depth);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -695,7 +695,7 @@ pix_bits_to_tgarle(uint8 *pbits, uint8 *ptga, color_space fromspace,
|
|||||||
uint16 nread = 0;
|
uint16 nread = 0;
|
||||||
status_t result, bytescopied = 0;
|
status_t result, bytescopied = 0;
|
||||||
uint8 *prawbuf, *praw;
|
uint8 *prawbuf, *praw;
|
||||||
prawbuf = new uint8[bitsBytesPerPixel * 128];
|
prawbuf = new(std::nothrow) uint8[bitsBytesPerPixel * 128];
|
||||||
praw = prawbuf;
|
praw = prawbuf;
|
||||||
if (!prawbuf)
|
if (!prawbuf)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -873,10 +873,10 @@ translate_from_bits_to_tgatc(BPositionIO *inSource,
|
|||||||
int32 tgaRowBytes = (imagespec.width * tgaBytesPerPixel) +
|
int32 tgaRowBytes = (imagespec.width * tgaBytesPerPixel) +
|
||||||
(imagespec.width / 2);
|
(imagespec.width / 2);
|
||||||
uint32 tgapixrow = 0;
|
uint32 tgapixrow = 0;
|
||||||
uint8 *tgaRowData = new uint8[tgaRowBytes];
|
uint8 *tgaRowData = new(std::nothrow) uint8[tgaRowBytes];
|
||||||
if (!tgaRowData)
|
if (!tgaRowData)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
uint8 *bitsRowData = new uint8[bitsRowBytes];
|
uint8 *bitsRowData = new(std::nothrow) uint8[bitsRowBytes];
|
||||||
if (!bitsRowData) {
|
if (!bitsRowData) {
|
||||||
delete[] tgaRowData;
|
delete[] tgaRowData;
|
||||||
tgaRowData = NULL;
|
tgaRowData = NULL;
|
||||||
@@ -966,17 +966,17 @@ translate_from_bits1_to_tgabw(BPositionIO *inSource,
|
|||||||
int32 tgaRowBytes = (imagespec.width * tgaBytesPerPixel) +
|
int32 tgaRowBytes = (imagespec.width * tgaBytesPerPixel) +
|
||||||
(imagespec.width / 2);
|
(imagespec.width / 2);
|
||||||
uint32 tgapixrow = 0;
|
uint32 tgapixrow = 0;
|
||||||
uint8 *tgaRowData = new uint8[tgaRowBytes];
|
uint8 *tgaRowData = new(std::nothrow) uint8[tgaRowBytes];
|
||||||
if (!tgaRowData)
|
if (!tgaRowData)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
uint8 *medRowData = new uint8[imagespec.width];
|
uint8 *medRowData = new(std::nothrow) uint8[imagespec.width];
|
||||||
if (!medRowData) {
|
if (!medRowData) {
|
||||||
delete[] tgaRowData;
|
delete[] tgaRowData;
|
||||||
tgaRowData = NULL;
|
tgaRowData = NULL;
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
uint8 *bitsRowData = new uint8[bitsRowBytes];
|
uint8 *bitsRowData = new(std::nothrow) uint8[bitsRowBytes];
|
||||||
if (!bitsRowData) {
|
if (!bitsRowData) {
|
||||||
delete[] medRowData;
|
delete[] medRowData;
|
||||||
medRowData = NULL;
|
medRowData = NULL;
|
||||||
@@ -1561,10 +1561,10 @@ TGATranslator::translate_from_tganm_to_bits(BPositionIO *inSource,
|
|||||||
outDestination->Seek(bitsoffset, SEEK_CUR);
|
outDestination->Seek(bitsoffset, SEEK_CUR);
|
||||||
|
|
||||||
// allocate row buffers
|
// allocate row buffers
|
||||||
uint8 *tgaRowData = new uint8[tgaRowBytes];
|
uint8 *tgaRowData = new(std::nothrow) uint8[tgaRowBytes];
|
||||||
if (!tgaRowData)
|
if (!tgaRowData)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
uint8 *bitsRowData = new uint8[bitsRowBytes];
|
uint8 *bitsRowData = new(std::nothrow) uint8[bitsRowBytes];
|
||||||
if (!bitsRowData) {
|
if (!bitsRowData) {
|
||||||
delete[] tgaRowData;
|
delete[] tgaRowData;
|
||||||
tgaRowData = NULL;
|
tgaRowData = NULL;
|
||||||
@@ -1658,7 +1658,7 @@ TGATranslator::translate_from_tganmrle_to_bits(BPositionIO *inSource,
|
|||||||
outDestination->Seek(bitsoffset, SEEK_CUR);
|
outDestination->Seek(bitsoffset, SEEK_CUR);
|
||||||
|
|
||||||
// allocate row buffers
|
// allocate row buffers
|
||||||
uint8 *bitsRowData = new uint8[bitsRowBytes];
|
uint8 *bitsRowData = new(std::nothrow) uint8[bitsRowBytes];
|
||||||
if (!bitsRowData)
|
if (!bitsRowData)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
@@ -1864,10 +1864,10 @@ translate_from_tgam_to_bits(BPositionIO *inSource,
|
|||||||
outDestination->Seek(bitsoffset, SEEK_CUR);
|
outDestination->Seek(bitsoffset, SEEK_CUR);
|
||||||
|
|
||||||
// allocate row buffers
|
// allocate row buffers
|
||||||
uint8 *tgaRowData = new uint8[tgaRowBytes];
|
uint8 *tgaRowData = new(std::nothrow) uint8[tgaRowBytes];
|
||||||
if (!tgaRowData)
|
if (!tgaRowData)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
uint8 *bitsRowData = new uint8[bitsRowBytes];
|
uint8 *bitsRowData = new(std::nothrow) uint8[bitsRowBytes];
|
||||||
if (!bitsRowData) {
|
if (!bitsRowData) {
|
||||||
delete[] tgaRowData;
|
delete[] tgaRowData;
|
||||||
tgaRowData = NULL;
|
tgaRowData = NULL;
|
||||||
@@ -1963,7 +1963,7 @@ TGATranslator::translate_from_tgamrle_to_bits(BPositionIO *inSource,
|
|||||||
outDestination->Seek(bitsoffset, SEEK_CUR);
|
outDestination->Seek(bitsoffset, SEEK_CUR);
|
||||||
|
|
||||||
// allocate row buffers
|
// allocate row buffers
|
||||||
uint8 *bitsRowData = new uint8[bitsRowBytes];
|
uint8 *bitsRowData = new(std::nothrow) uint8[bitsRowBytes];
|
||||||
if (!bitsRowData)
|
if (!bitsRowData)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
@@ -2130,7 +2130,7 @@ TGATranslator::translate_from_tga(BPositionIO *inSource, uint32 outType,
|
|||||||
nentrybytes = mapspec.entrysize / 8;
|
nentrybytes = mapspec.entrysize / 8;
|
||||||
if (mapspec.entrysize % 8)
|
if (mapspec.entrysize % 8)
|
||||||
nentrybytes++;
|
nentrybytes++;
|
||||||
ptgapalette = new uint8[nentrybytes * mapspec.length];
|
ptgapalette = new(std::nothrow) uint8[nentrybytes * mapspec.length];
|
||||||
inSource->Read(ptgapalette, nentrybytes * mapspec.length);
|
inSource->Read(ptgapalette, nentrybytes * mapspec.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2214,7 +2214,7 @@ TGATranslator::DerivedTranslate(BPositionIO *inSource,
|
|||||||
BView *
|
BView *
|
||||||
TGATranslator::NewConfigView(TranslatorSettings *settings)
|
TGATranslator::NewConfigView(TranslatorSettings *settings)
|
||||||
{
|
{
|
||||||
return new TGAView(B_TRANSLATE("TGATranslator Settings"),
|
return new(std::nothrow) TGAView(B_TRANSLATE("TGATranslator Settings"),
|
||||||
B_WILL_DRAW, settings);
|
B_WILL_DRAW, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user