avoid divide-by-zero in allocating 0x0 surface
authorvladimir@pobox.com
Thu, 02 Aug 2007 06:04:39 -0700
changeset 4158 71bf16e942c3444313b5e23e35314e6b455efdf4
parent 4157 f446c5648201251cb9c9a3dee0f9299d48521538
child 4159 c341e320bedb32f1e84528954dae2d5feb9d43ad
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9a7pre
avoid divide-by-zero in allocating 0x0 surface
gfx/cairo/cairo/src/cairo-quartz-surface.c
--- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
+++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
@@ -1676,16 +1676,24 @@ cairo_quartz_surface_create (cairo_forma
     cairo_quartz_surface_t *surf;
     CGContextRef cgc;
     CGColorSpaceRef cgColorspace;
     CGBitmapInfo bitinfo;
     void *imageData;
     int stride;
     int bitsPerComponent;
 
+    unsigned int realWidth = width;
+    unsigned int realHeight = height;
+
+    if (width == 0)
+	width = 1;
+    if (height == 0)
+	height = 1;
+
     if (format == CAIRO_FORMAT_ARGB32) {
 	cgColorspace = CGColorSpaceCreateDeviceRGB();
 	stride = width * 4;
 	bitinfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
 	bitsPerComponent = 8;
     } else if (format == CAIRO_FORMAT_RGB24) {
 	cgColorspace = CGColorSpaceCreateDeviceRGB();
 	stride = width * 4;
@@ -1732,17 +1740,17 @@ cairo_quartz_surface_create (cairo_forma
 	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
     /* flip the Y axis */
     CGContextTranslateCTM (cgc, 0.0, height);
     CGContextScaleCTM (cgc, 1.0, -1.0);
 
     surf = _cairo_quartz_surface_create_internal (cgc, _cairo_content_from_format (format),
-						   width, height);
+						  realWidth, realHeight);
     if (!surf) {
 	CGContextRelease (cgc);
 	// create_internal will have set an error
 	return (cairo_surface_t*) &_cairo_surface_nil;
     }
 
     surf->imageData = imageData;