From c9fc6e0f791c29721d51893d086aaaccc38f0e87 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Wed, 8 May 2019 00:59:40 +0100 Subject: [PATCH] Consistently check for failed memory allocation --- src/osgPlugins/tga/ReaderWriterTGA.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/osgPlugins/tga/ReaderWriterTGA.cpp b/src/osgPlugins/tga/ReaderWriterTGA.cpp index 79e70da55..5499412bc 100644 --- a/src/osgPlugins/tga/ReaderWriterTGA.cpp +++ b/src/osgPlugins/tga/ReaderWriterTGA.cpp @@ -356,6 +356,11 @@ int *numComponents_ret) colormapLen = getInt16(&header[5]); colormapDepth = (header[7] + 7) >> 3; colormap.reinitialise(colormapLen*colormapDepth); + if (colormap == NULL) + { + tgaerror = ERR_MEM; + return NULL; + } fin.read((char*)colormap, colormapLen*colormapDepth); if (colormapDepth == 2) /* 16 bits */ @@ -387,6 +392,12 @@ int *numComponents_ret) bpr = format * width; SafeArray linebuf(width * depth); + if (buffer == NULL || linebuf == NULL) + { + tgaerror = ERR_MEM; + return NULL; + } + //check the intended image orientation bool bLeftToRight = (flags&0x10)==0; bool bTopToBottom = (flags&0x20)!=0; @@ -404,6 +415,11 @@ int *numComponents_ret) return NULL; } SafeArray formattedMap(colormapLen * format); + if (formattedMap == NULL) + { + tgaerror = ERR_MEM; + return NULL; + } for (int i = 0; i < colormapLen; i++) { convert_data(colormap, formattedMap, i, colormapDepth, format);