From 55ce0b774869e9fa614c6f9fec7905f7205cb5ff Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Fri, 5 Feb 2010 22:30:05 +0100 Subject: [PATCH] script: Fix script scanner endianness The script interpreter was reading the length of compressed data as an host-endian uint32_t, thus making cairo-script able to correctly read traces that were produced on the same endianness as the one they ran upon, but unsuitable for portabile cairo-scripts. Reviewed-by: Chris Wilson --- util/cairo-script/cairo-script-scanner.c | 30 ++++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/util/cairo-script/cairo-script-scanner.c b/util/cairo-script/cairo-script-scanner.c index 0422fe066..24d1616f2 100644 --- a/util/cairo-script/cairo-script-scanner.c +++ b/util/cairo-script/cairo-script-scanner.c @@ -43,6 +43,20 @@ #define DEBUG_SCAN 0 +#if WORDS_BIGENDIAN +#define le16(x) bswap_16 (x) +#define le32(x) bswap_32 (x) +#define be16(x) x +#define be32(x) x +#define to_be32(x) x +#else +#define le16(x) x +#define le32(x) x +#define be16(x) bswap_16 (x) +#define be32(x) bswap_32 (x) +#define to_be32(x) bswap_32 (x) +#endif + /* * whitespace: * 0 - nul @@ -639,7 +653,7 @@ base85_end (csi_t *ctx, csi_scanner_t *scan, cairo_bool_t deflate) } if (deflate) { - uLongf len = *(uint32_t *) scan->buffer.base; + uLongf len = be32 (*(uint32_t *) scan->buffer.base); Bytef *source = (Bytef *) (scan->buffer.base + sizeof (uint32_t)); status = csi_string_deflate_new (ctx, &obj, @@ -766,20 +780,6 @@ scan_read (csi_scanner_t *scan, csi_file_t *src, void *ptr, int len) } while (_csi_unlikely (len)); } -#if WORDS_BIGENDIAN -#define le16(x) bswap_16 (x) -#define le32(x) bswap_32 (x) -#define be16(x) x -#define be32(x) x -#define to_be32(x) x -#else -#define le16(x) x -#define le32(x) x -#define be16(x) bswap_16 (x) -#define be32(x) bswap_32 (x) -#define to_be32(x) bswap_32 (x) -#endif - static void string_read (csi_t *ctx, csi_scanner_t *scan,