[cairo-commit] 3 commits - boilerplate/cairo-boilerplate.c src/cairo-clip.c src/cairo-region.c

Chris Wilson ickle at kemper.freedesktop.org
Sun Sep 23 13:38:05 PDT 2007


 boilerplate/cairo-boilerplate.c |    5 -----
 src/cairo-clip.c                |   38 ++++++++++++++++++++++----------------
 src/cairo-region.c              |    4 +++-
 3 files changed, 25 insertions(+), 22 deletions(-)

New commits:
diff-tree dc23ecb6198f1e28b6096cbef931e15407cc20a8 (from 4f7c5a5033f41de94a7ea284a64f4afa0900fff1)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Sep 23 21:02:31 2007 +0100

    [cairo-boilerplate] Do not throw an error if an exclude target is not found.
    
    If we fail to exclude a target because it was not in the list of
    targets - job done and no need to throw a tantrum.

diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index 34846d2..4d7c7e9 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -417,11 +417,6 @@ cairo_boilerplate_get_targets (int *pnum
 	    }
 	    num_targets = j;
 
-	    if (!found) {
-		fprintf (stderr, "Cannot find target '%.*s'\n", (int)(end - tname), tname);
-		exit(-1);
-	    }
-
 	    if (*end)
 	      end++;
 	    tname = end;
diff-tree 4f7c5a5033f41de94a7ea284a64f4afa0900fff1 (from 45feb13c2689a8f5813e60fb0c2d17e9e02fd4b5)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Sep 23 21:04:36 2007 +0100

    [cairo-region] Call _cairo_error() at original error site.
    
    Before returning a fresh CAIRO_STATUS_NO_MEMORY, remember to call
    cairo_error().

diff --git a/src/cairo-region.c b/src/cairo-region.c
index 4fe6832..e5889c7 100644
--- a/src/cairo-region.c
+++ b/src/cairo-region.c
@@ -124,8 +124,10 @@ _cairo_region_get_boxes (cairo_region_t 
     }
 
     cboxes = _cairo_malloc_ab (nboxes, sizeof(cairo_box_int_t));
-    if (cboxes == NULL)
+    if (cboxes == NULL) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
 	return CAIRO_STATUS_NO_MEMORY;
+    }
 
     for (i = 0; i < nboxes; i++) {
 	cboxes[i].p1.x = pboxes[i].x1;
diff-tree 45feb13c2689a8f5813e60fb0c2d17e9e02fd4b5 (from 77f1aa78872aa108199afd41247cf21827f7e33a)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Sep 23 21:34:50 2007 +0100

    [cairo-clip] Avoid a malloc(0).
    
    Avoid a potential allocation of 0 bytes, and a potential NULL leading to an
    incorrect CAIRO_STATUS_NO_MEMORY, when copying an empty clip region.

diff --git a/src/cairo-clip.c b/src/cairo-clip.c
index c9ad85e..214b408 100644
--- a/src/cairo-clip.c
+++ b/src/cairo-clip.c
@@ -635,23 +635,26 @@ _cairo_clip_copy_rectangle_list (cairo_c
 	if (_cairo_region_get_boxes (&clip->region, &n_boxes, &boxes) != CAIRO_STATUS_SUCCESS)
 	    return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
 
-	rectangles = _cairo_malloc_ab (n_boxes, sizeof (cairo_rectangle_t));
-	if (rectangles == NULL) {
-	    _cairo_region_boxes_fini (&clip->region, boxes);
-	    return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
-	}
-
-        for (i = 0; i < n_boxes; ++i) {
-	    cairo_rectangle_int_t clip_rect = { boxes[i].p1.x, boxes[i].p1.y,
-						boxes[i].p2.x - boxes[i].p1.x,
-						boxes[i].p2.y - boxes[i].p1.y };
-
-            if (!_cairo_clip_int_rect_to_user(gstate, &clip_rect, &rectangles[i])) {
+	if (n_boxes) {
+	    rectangles = _cairo_malloc_ab (n_boxes, sizeof (cairo_rectangle_t));
+	    if (rectangles == NULL) {
 		_cairo_region_boxes_fini (&clip->region, boxes);
-		free (rectangles);
-		return (cairo_rectangle_list_t*) &_cairo_rectangles_not_representable;
+		_cairo_error (CAIRO_STATUS_NO_MEMORY);
+		return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
 	    }
-        }
+
+	    for (i = 0; i < n_boxes; ++i) {
+		cairo_rectangle_int_t clip_rect = { boxes[i].p1.x, boxes[i].p1.y,
+						    boxes[i].p2.x - boxes[i].p1.x,
+						    boxes[i].p2.y - boxes[i].p1.y };
+
+		if (!_cairo_clip_int_rect_to_user(gstate, &clip_rect, &rectangles[i])) {
+		    _cairo_region_boxes_fini (&clip->region, boxes);
+		    free (rectangles);
+		    return (cairo_rectangle_list_t*) &_cairo_rectangles_not_representable;
+		}
+	    }
+	}
 
 	_cairo_region_boxes_fini (&clip->region, boxes);
     } else {
@@ -660,8 +663,10 @@ _cairo_clip_copy_rectangle_list (cairo_c
 	n_boxes = 1;
 
 	rectangles = malloc(sizeof (cairo_rectangle_t));
-	if (rectangles == NULL)
+	if (rectangles == NULL) {
+	    _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	    return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
+	}
 
 	if (_cairo_surface_get_extents (_cairo_gstate_get_target (gstate), &extents) ||
 	    !_cairo_clip_int_rect_to_user(gstate, &extents, rectangles))
@@ -674,6 +679,7 @@ _cairo_clip_copy_rectangle_list (cairo_c
     list = malloc (sizeof (cairo_rectangle_list_t));
     if (list == NULL) {
         free (rectangles);
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
         return (cairo_rectangle_list_t*) &_cairo_rectangles_nil;
     }
     


More information about the cairo-commit mailing list