[cairo-commit] src/cairo-misc.c src/cairo-types-private.h

Behdad Esfahbod behdad at kemper.freedesktop.org
Tue Jun 24 12:02:50 PDT 2008


 src/cairo-misc.c          |    2 ++
 src/cairo-types-private.h |   13 ++++++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

New commits:
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.

diff --git a/src/cairo-misc.c b/src/cairo-misc.c
index e2b7cf7..30686a0 100644
--- a/src/cairo-misc.c
+++ b/src/cairo-misc.c
@@ -38,6 +38,8 @@
 
 #include "cairoint.h"
 
+COMPILE_TIME_ASSERT (CAIRO_STATUS_LAST_STATUS < CAIRO_INT_STATUS_UNSUPPORTED);
+COMPILE_TIME_ASSERT (CAIRO_INT_STATUS_LAST_STATUS <= 127);
 
 /**
  * cairo_status_to_string:
diff --git a/src/cairo-types-private.h b/src/cairo-types-private.h
index 0b66df2..36661e4 100644
--- a/src/cairo-types-private.h
+++ b/src/cairo-types-private.h
@@ -130,16 +130,19 @@ typedef enum _cairo_paginated_mode {
 } cairo_paginated_mode_t;
 
 /* Sure wish C had a real enum type so that this would be distinct
- * from #cairo_status_t. Oh well, without that, I'll use this bogus 1000
- * offset */
+ * from #cairo_status_t. Oh well, without that, I'll use this bogus 100
+ * offset.  We want to keep it fit in int8_t as the compiler may choose
+ * that for cairo_status_t */
 typedef enum _cairo_int_status {
-    CAIRO_INT_STATUS_DEGENERATE = 1000,
-    CAIRO_INT_STATUS_UNSUPPORTED,
+    CAIRO_INT_STATUS_UNSUPPORTED = 100,
+    CAIRO_INT_STATUS_DEGENERATE,
     CAIRO_INT_STATUS_NOTHING_TO_DO,
     CAIRO_INT_STATUS_CACHE_EMPTY,
     CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY,
     CAIRO_INT_STATUS_IMAGE_FALLBACK,
-    CAIRO_INT_STATUS_ANALYZE_META_SURFACE_PATTERN
+    CAIRO_INT_STATUS_ANALYZE_META_SURFACE_PATTERN,
+
+    CAIRO_INT_STATUS_LAST_STATUS
 } cairo_int_status_t;
 
 typedef enum _cairo_internal_surface_type {


More information about the cairo-commit mailing list