[Mesa-dev] [PATCH 1/6] mesa/main: in _mesa_unpack_color_index_to_rgba_ubyte() check allocated pointers
Juha-Pekka Heikkila
juhapekka.heikkila at gmail.com
Mon Jan 26 01:07:46 PST 2015
Check we really got memory we were asking for.
Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
---
src/mesa/main/pack.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index d1f368c..da2128d 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -1611,9 +1611,17 @@ _mesa_unpack_color_index_to_rgba_ubyte(struct gl_context *ctx, GLuint dims,
src, srcFormat, srcType,
srcWidth, srcHeight, srcDepth,
srcPacking, transferOps);
+ if (!rgba)
+ return NULL;
count = srcWidth * srcHeight * srcDepth;
dst = malloc(count * 4 * sizeof(GLubyte));
+ if (!dst) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
+ free(rgba);
+ return NULL;
+ }
+
for (i = 0; i < count; i++) {
CLAMPED_FLOAT_TO_UBYTE(dst[i * 4 + 0], rgba[i * 4 + 0]);
CLAMPED_FLOAT_TO_UBYTE(dst[i * 4 + 1], rgba[i * 4 + 1]);
--
1.8.5.1
More information about the mesa-dev
mailing list