[Bf-blender-cvs] [c193dbe] master: Fix T37826: Opening a new image in the image editor

Sergey Sharybin noreply at git.blender.org
Mon Dec 16 11:52:01 CET 2013


Commit: c193dbe30b40beb435d6edde7117469f4706f98e
Author: Sergey Sharybin
Date:   Mon Dec 16 16:42:48 2013 +0600
http://developer.blender.org/rBc193dbe30b40beb435d6edde7117469f4706f98e

Fix T37826: Opening a new image in the image editor

Cast dimensions to size_t before multiplication.
Also made add_ibuf_size survive cases when image
buffer allocation failed.

===================================================================

M	source/blender/blenkernel/intern/image.c
M	source/blender/imbuf/intern/allocimbuf.c

===================================================================

diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 41b2b1d..40149c6 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -682,7 +682,6 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char
 
 	if (floatbuf) {
 		ibuf = IMB_allocImBuf(width, height, depth, IB_rectfloat);
-		rect_float = ibuf->rect_float;
 
 		if (colorspace_settings->name[0] == '\0') {
 			const char *colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_FLOAT);
@@ -690,11 +689,13 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char
 			BLI_strncpy(colorspace_settings->name, colorspace, sizeof(colorspace_settings->name));
 		}
 
-		IMB_colormanagement_check_is_data(ibuf, colorspace_settings->name);
+		if (ibuf != NULL) {
+			rect_float = ibuf->rect_float;
+			IMB_colormanagement_check_is_data(ibuf, colorspace_settings->name);
+		}
 	}
 	else {
 		ibuf = IMB_allocImBuf(width, height, depth, IB_rect);
-		rect = (unsigned char *)ibuf->rect;
 
 		if (colorspace_settings->name[0] == '\0') {
 			const char *colorspace = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_BYTE);
@@ -702,7 +703,14 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char
 			BLI_strncpy(colorspace_settings->name, colorspace, sizeof(colorspace_settings->name));
 		}
 
-		IMB_colormanagement_assign_rect_colorspace(ibuf, colorspace_settings->name);
+		if (ibuf != NULL) {
+			rect = (unsigned char *)ibuf->rect;
+			IMB_colormanagement_assign_rect_colorspace(ibuf, colorspace_settings->name);
+		}
+	}
+
+	if (!ibuf) {
+		return NULL;
 	}
 
 	BLI_strncpy(ibuf->name, name, sizeof(ibuf->name));
diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c
index 73d28cd..d7ca381 100644
--- a/source/blender/imbuf/intern/allocimbuf.c
+++ b/source/blender/imbuf/intern/allocimbuf.c
@@ -201,7 +201,7 @@ bool addzbufImBuf(ImBuf *ibuf)
 	
 	IMB_freezbufImBuf(ibuf);
 	
-	size = (size_t)(ibuf->x * ibuf->y) * sizeof(unsigned int);
+	size = (size_t)ibuf->x * (size_t)ibuf->y * sizeof(unsigned int);
 
 	if ((ibuf->zbuf = MEM_mapallocN(size, __func__))) {
 		ibuf->mall |= IB_zbuf;
@@ -220,7 +220,7 @@ bool addzbuffloatImBuf(ImBuf *ibuf)
 	
 	IMB_freezbuffloatImBuf(ibuf);
 	
-	size = (size_t)(ibuf->x * ibuf->y) * sizeof(float);
+	size = (size_t)ibuf->x * (size_t)ibuf->y * sizeof(float);
 
 	if ((ibuf->zbuf_float = MEM_mapallocN(size, __func__))) {
 		ibuf->mall |= IB_zbuffloat;
@@ -300,7 +300,7 @@ bool imb_addrectfloatImBuf(ImBuf *ibuf)
 	if (ibuf->rect_float)
 		imb_freerectfloatImBuf(ibuf);  /* frees mipmap too, hrm */
 	
-	size = (size_t)(ibuf->x * ibuf->y) * sizeof(float[4]);
+	size = (size_t)ibuf->x * (size_t)ibuf->y * sizeof(float[4]);
 
 	ibuf->channels = 4;
 	if ((ibuf->rect_float = MEM_mapallocN(size, __func__))) {
@@ -324,7 +324,7 @@ bool imb_addrectImBuf(ImBuf *ibuf)
 		MEM_freeN(ibuf->rect);
 	ibuf->rect = NULL;
 	
-	size = (size_t)(ibuf->x * ibuf->y) * sizeof(unsigned int);
+	size = (size_t)ibuf->x * (size_t)ibuf->y * sizeof(unsigned int);
 
 	if ((ibuf->rect = MEM_mapallocN(size, __func__))) {
 		ibuf->mall |= IB_rect;




More information about the Bf-blender-cvs mailing list