[cairo] [PATCH 7/8] mesh: Avoid theoretical infinite loops

Chris Wilson chris at chris-wilson.co.uk
Sat Feb 22 03:52:20 PST 2014


On Sat, Feb 22, 2014 at 02:07:07AM +0000, Bryce W. Harrington wrote:
> This quells this warning:
> 
>   src/cairo-mesh-pattern-rasterizer.c:731:5: warning: cannot
>   optimize possibly infinite loops
> 
> I guess the compiler's complaining because if vsteps were negative or
> equal to UINT_MAX the loop could cycle infinitely.  Silly compiler.

Slightly less worrisome:

diff --git a/src/cairo-mesh-pattern-rasterizer.c b/src/cairo-mesh-pattern-rasterizer.c
index 6f0dd66..548e880 100644
--- a/src/cairo-mesh-pattern-rasterizer.c
+++ b/src/cairo-mesh-pattern-rasterizer.c
@@ -697,9 +697,9 @@ rasterize_bezier_patch (unsigned char *data, int width, int height, int stride,
                        cairo_point_double_t p[4][4], double col[4][4])
 {
     double pv[4][2][4], cstart[4], cend[4], dcstart[4], dcend[4];
-    int vsteps, v, i, k;
+    int v, i, k;
 
-    vsteps = 1 << vshift;
+    v = 1 << vshift;
 
     /*
      * pv[i][0] is the function (represented using forward
@@ -724,11 +724,11 @@ rasterize_bezier_patch (unsigned char *data, int width, int height, int stride,
     for (i = 0; i < 4; ++i) {
        cstart[i]  = col[0][i];
        cend[i]    = col[1][i];
-       dcstart[i] = (col[2][i] - col[0][i]) / vsteps;
-       dcend[i]   = (col[3][i] - col[1][i]) / vsteps;
+       dcstart[i] = (col[2][i] - col[0][i]) / v;
+       dcend[i]   = (col[3][i] - col[1][i]) / v;
     }
 
-    for (v = 0; v <= vsteps; ++v) {
+    while (v--) {

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the cairo mailing list