[cairo-commit] 2 commits - src/cairo-atsui-font.c src/cairoint.h src/cairo-surface.c src/cairo-xcb-surface.c src/cairo-xlib-surface.c

Carl Worth cworth at kemper.freedesktop.org
Tue May 2 11:42:08 PDT 2006


 src/cairo-atsui-font.c   |    8 +++++++-
 src/cairo-surface.c      |    2 +-
 src/cairo-xcb-surface.c  |    5 +++--
 src/cairo-xlib-surface.c |   19 +++++++++++--------
 src/cairoint.h           |    4 ++++
 5 files changed, 26 insertions(+), 12 deletions(-)

New commits:
diff-tree e59f35291fa5f97acfe408b7bce8652ec20566c8 (from 41e288a88023cac9ced77099bceced41cf526a99)
Author: Carl Worth <cworth at cworth.org>
Date:   Tue May 2 11:36:41 2006 -0700

    atsui: Add missing check of return-value of malloc.
    
    This addresses the original problem noted in mozilla's bug #336129:
    
    	Missing out-of-memory check at gfx/cairo/cairo/src/cairo-atsui-font.c:185
    	https://bugzilla.mozilla.org/show_bug.cgi?id=336129
    
    This also adds a comment pointing out another malloc that is not
    checked, (but does not fix it).

diff --git a/src/cairo-atsui-font.c b/src/cairo-atsui-font.c
index 76b5a3c..5e6079e 100644
--- a/src/cairo-atsui-font.c
+++ b/src/cairo-atsui-font.c
@@ -211,6 +211,8 @@ _cairo_atsui_font_create_scaled (cairo_f
     cairo_status_t status;
 
     font = malloc(sizeof(cairo_atsui_font_t));
+    if (font == NULL)
+	return CAIRO_STATUS_NO_MEMORY;
 
     _cairo_scaled_font_init(&font->base, font_face, font_matrix, ctm, options,
 			    &cairo_atsui_scaled_font_backend);
@@ -640,7 +642,11 @@ _cairo_atsui_font_old_show_glyphs (void	
 	    CGRect stack_rects[10];
 	    CGRect *rects;
 	    int i;
-	    
+
+	    /* XXX: Return-value of malloc needs to be checked for
+	     * NULL. Can someone fix this who is more familiar with
+	     * the cleanup needed in this function?
+	     */
 	    if (num_boxes > 10)
 		rects = malloc (sizeof (CGRect) * num_boxes);
 	    else
diff-tree 41e288a88023cac9ced77099bceced41cf526a99 (from 0e4527c67e623801544be05de32f21a0c10e5b5d)
Author: Carl Worth <cworth at cworth.org>
Date:   Mon May 1 15:44:58 2006 -0700

    Make backend-specific function set a surface error on type mismatch.
    
    If any backend-specific, surface-modifying function is called with
    the wrong surface type we set an error on that surface.

diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 9a15db4..f905dfd 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -108,7 +108,7 @@ const cairo_surface_t _cairo_surface_nil
  * breakpoint in _cairo_error() to generate a stack trace for when the
  * user causes cairo to detect an error.
  **/
-static void
+void
 _cairo_surface_set_error (cairo_surface_t *surface,
 			  cairo_status_t status)
 {
diff --git a/src/cairo-xcb-surface.c b/src/cairo-xcb-surface.c
index 78eafc0..1e90f10 100644
--- a/src/cairo-xcb-surface.c
+++ b/src/cairo-xcb-surface.c
@@ -1291,9 +1291,10 @@ cairo_xcb_surface_set_size (cairo_surfac
 {
     cairo_xcb_surface_t *xcb_surface = (cairo_xcb_surface_t *)surface;
 
-    /* XXX: How do we want to handle this error case? */
-    if (! _cairo_surface_is_xcb (surface))
+    if (! _cairo_surface_is_xcb (surface)) {
+	_cairo_surface_set_error (surface, CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
 	return;
+    }
 
     xcb_surface->width = width;
     xcb_surface->height = height;
diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 91bb178..3245af6 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -1947,18 +1947,20 @@ cairo_xlib_surface_create_with_xrender_f
  * this function on a surface created for a Pixmap.
  **/
 void
-cairo_xlib_surface_set_size (cairo_surface_t *surface,
+cairo_xlib_surface_set_size (cairo_surface_t *abstract_surface,
 			     int              width,
 			     int              height)
 {
-    cairo_xlib_surface_t *xlib_surface = (cairo_xlib_surface_t *)surface;
+    cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface;
 
-    /* XXX: How do we want to handle this error case? */
-    if (! _cairo_surface_is_xlib (surface))
+    if (! _cairo_surface_is_xlib (abstract_surface)) {
+	_cairo_surface_set_error (abstract_surface,
+				  CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
 	return;
+    }
 
-    xlib_surface->width = width;
-    xlib_surface->height = height;
+    surface->width = width;
+    surface->height = height;
 }
 /**
  * cairo_xlib_surface_set_drawable:
@@ -1982,9 +1984,10 @@ cairo_xlib_surface_set_drawable (cairo_s
 {
     cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *)abstract_surface;
 
-    /* XXX: How do we want to handle this error case? */
-    if (! _cairo_surface_is_xlib (abstract_surface))
+    if (! _cairo_surface_is_xlib (abstract_surface)) {
+	_cairo_surface_set_error (abstract_surface, CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
 	return;
+    }
 
     /* XXX: and what about this case? */
     if (surface->owns_pixmap)
diff --git a/src/cairoint.h b/src/cairoint.h
index 65b482f..cfa8b7d 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1607,6 +1607,10 @@ extern const cairo_private cairo_surface
 extern const cairo_private cairo_surface_t _cairo_surface_nil_read_error;
 extern const cairo_private cairo_surface_t _cairo_surface_nil_file_not_found;
 
+cairo_private void
+_cairo_surface_set_error (cairo_surface_t	*surface,
+			  cairo_status_t	 status);
+
 cairo_private cairo_surface_t *
 _cairo_surface_create_similar_scratch (cairo_surface_t *other,
 				       cairo_content_t	content,


More information about the cairo-commit mailing list