PNGTranslator: Fix PVS 2237-2241

* 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: I23df98e58ea1960463e86a75ff69d67855f59074
Reviewed-on: https://review.haiku-os.org/690
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Murai Takashi
2018-11-13 19:58:08 +00:00
committed by waddlesplash
parent 99b0a7e0ed
commit 6c8b0b3724
+12 -11
View File
@@ -133,7 +133,7 @@ BTranslator *
make_nth_translator(int32 n, image_id you, uint32 flags, ...)
{
if (!n)
return new PNGTranslator();
return new(std::nothrow) PNGTranslator();
else
return NULL;
}
@@ -193,7 +193,7 @@ pngcb_flush_data(png_structp ppng)
// Returns:
// ---------------------------------------------------------------
PNGTranslator::PNGTranslator()
: BaseTranslator(B_TRANSLATE("PNG images"),
: BaseTranslator(B_TRANSLATE("PNG images"),
B_TRANSLATE("PNG image translator"),
PNG_TRANSLATOR_VERSION,
sInputFormats, kNumInputFormats,
@@ -433,7 +433,7 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
if (interlace_type == PNG_INTERLACE_NONE) {
// allocate buffer for storing PNG row
prow = new uint8[rowbytes];
prow = new(std::nothrow) uint8[rowbytes];
if (!prow) {
result = B_NO_MEMORY;
break;
@@ -452,14 +452,14 @@ PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
} else {
// interlaced PNG image
prows = new uint8 *[height];
prows = new(std::nothrow) uint8 *[height];
if (!prows) {
result = B_NO_MEMORY;
break;
}
// allocate enough memory to store the whole image
for (nalloc = 0; nalloc < height; nalloc++) {
prows[nalloc] = new uint8[rowbytes];
prows[nalloc] = new(std::nothrow) uint8[rowbytes];
if (!prows[nalloc])
break;
}
@@ -853,26 +853,27 @@ PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
pngcb_write_data, pngcb_flush_data);
// Allocate memory needed to buffer image data
pbitsrow = new uint8[bitsHeader.rowBytes];
pbitsrow = new(std::nothrow) uint8[bitsHeader.rowBytes];
if (!pbitsrow) {
result = B_NO_MEMORY;
break;
}
if (interlace_type == PNG_INTERLACE_NONE) {
prow = new uint8[width * pngBytesPerPixel];
prow = new(std::nothrow) uint8[width * pngBytesPerPixel];
if (!prow) {
result = B_NO_MEMORY;
break;
}
} else {
prows = new uint8 *[height];
prows = new(std::nothrow) uint8 *[height];
if (!prows) {
result = B_NO_MEMORY;
break;
}
// allocate enough memory to store the whole image
for (nalloc = 0; nalloc < height; nalloc++) {
prows[nalloc] = new uint8[width * pngBytesPerPixel];
prows[nalloc] =
new(std::nothrow) uint8[width * pngBytesPerPixel];
if (!prows[nalloc])
break;
}
@@ -1001,8 +1002,8 @@ PNGTranslator::DerivedTranslate(BPositionIO *inSource,
BView *
PNGTranslator::NewConfigView(TranslatorSettings *settings)
{
return new PNGView(BRect(0, 0, PNG_VIEW_WIDTH, PNG_VIEW_HEIGHT),
B_TRANSLATE("PNGTranslator Settings"), B_FOLLOW_ALL,
return new(std::nothrow) PNGView(BRect(0, 0, PNG_VIEW_WIDTH, PNG_VIEW_HEIGHT),
B_TRANSLATE("PNGTranslator Settings"), B_FOLLOW_ALL,
B_WILL_DRAW, settings);
}