[cairo] [PATCH] make sure compilers don't optimize cairo_status_t to unsigned char

Behdad Esfahbod behdad at behdad.org
Tue Jun 24 12:02:48 PDT 2008


Hi,

I pushed a fix.  Thanks.

behdad


commit ace3a98a53ab596c83df5a163e580770b9771bf2
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Jun 24 15:02:14 2008 -0400

    Make sure cairo_int_status_t values fit in int8_t
    
    It was reported by Liu Yubao that cairo_status_t may be chosen to be
    an int8_t by the compiler, in that case cairo_int_status_t values
    assigned to cairo_status_t would overflow.  Fix this by allocating
    the values in int8_t range, and add compile-time sanity checks.



On Tue, 2008-06-24 at 14:01 +0800, Liu Yubao wrote:
> Hi,
> 
> I use a GCC 4.2.1 cross compiling toolchain to build cairo-1.6.4 and find a problem. 
> In cairo-clip.c:557:_cairo_clip_clip() function:
> 
>     status = _cairo_clip_intersect_path (clip,
>                                          path, fill_rule, tolerance,
>                                          antialias);
>     if (status == CAIRO_STATUS_SUCCESS)
>         clip->serial = _cairo_surface_allocate_clip_serial (target);
> 
>     if (status != CAIRO_INT_STATUS_UNSUPPORTED)
>         return status;
> 
> The _cairo_clip_intersect_path() function returns CAIRO_INT_STATUS_UNSUPPORTED for a
> cairo_image_surface_t, I guess the -O2 option make cairo_status_t be optimized to unsigned
> char by GCC 4.2.1, so the "status" variable becomes 233 and the 
> "status != CAIRO_INT_STATUS_UNSUPPORTED" condition becomes true wrongly.
> 
> I googled the web and find some GCC options related to that optimization:
> 
>     -fenum-int-equiv
>     -fshort-enums
>     -enum int
> 
> Somebody says these options can lead to binary incompatibility problem and my project
> doesn't specify these explicitly, so I think it's better to modify cairo's code to prevent
> that optimization. 
> 
> Best regards,
> Liu Yubao
> 
> diff --git a/src/cairo.h b/src/cairo.h
> index 4a3a773..8b791cd 100644
> --- a/src/cairo.h
> +++ b/src/cairo.h
> @@ -237,8 +237,10 @@ typedef enum _cairo_status {
>      CAIRO_STATUS_INVALID_INDEX,
>      CAIRO_STATUS_CLIP_NOT_REPRESENTABLE,
>      CAIRO_STATUS_TEMP_FILE_ERROR,
> -    CAIRO_STATUS_INVALID_STRIDE
> +    CAIRO_STATUS_INVALID_STRIDE,
>      /* after adding a new error: update CAIRO_STATUS_LAST_STATUS in cairoint.h */
> +
> +    CAIRO_STATUS_DONT_OPTIMIZE_ENUM_TO_UNSIGNED_CHAR = 0x00FFFFFF
>  } cairo_status_t;
> 
>  /**
> 
> 
> 
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759



More information about the cairo mailing list