[Pixman] [PATCH 1/1] enable stride*height > 2^31

LE GARREC Vincent legarrec.vincent at gmail.com
Sat Sep 28 01:57:25 PDT 2013


Please, find enclose the patch to make pixman compatible with stride*height.
I create a macro #define STRIDE_MULT(stride, height)
((ssize_t)(stride)*(height)) and replace every multiplication.
I also change make_random_bytes (int n_bytes); by make_random_bytes (size_t
n_bytes); in utils.c and utils.h

make check of course do not fails for me but I didn't change anything to
test when stride*height > 2^31

This patch needs review and some tests needs to be add when stride*height >
2^31

diff --git a/demos/gtk-utils.c b/demos/gtk-utils.c
index 32d4aec..f9eee7f 100644
--- a/demos/gtk-utils.c
+++ b/demos/gtk-utils.c
@@ -83,8 +83,8 @@ pixbuf_from_argb32 (uint32_t *bits,

     for (i = 0; i < height; ++i)
     {
-    uint32_t *src_row = &bits[i * (stride / 4)];
-    uint32_t *dst_row = p_bits + i * (p_stride / 4);
+    uint32_t *src_row = &bits[STRIDE_MULT (i, stride / 4)];
+    uint32_t *dst_row = p_bits + STRIDE_MULT (i, p_stride / 4);

     a8r8g8b8_to_rgba_np (dst_row, src_row, width);
     }
diff --git a/pixman/pixman-access.c b/pixman/pixman-access.c
index 4f0642d..ce0191c 100644
--- a/pixman/pixman-access.c
+++ b/pixman/pixman-access.c
@@ -164,15 +164,15 @@
  * YV12 setup and access macros
  */

-#define YV12_SETUP(image)                                               \
-    bits_image_t *__bits_image = (bits_image_t *)image;                 \
-    uint32_t *bits = __bits_image->bits;                                \
-    int stride = __bits_image->rowstride;                               \
-    int offset0 = stride < 0 ?                                          \
-    ((-stride) >> 1) * ((__bits_image->height - 1) >> 1) - stride :    \
-    stride * __bits_image->height;                    \
-    int offset1 = stride < 0 ?                                          \
-    offset0 + ((-stride) >> 1) * ((__bits_image->height) >> 1) :    \
+#define
YV12_SETUP(image)                                                       \
+    bits_image_t *__bits_image = (bits_image_t
*)image;                         \
+    uint32_t *bits =
__bits_image->bits;                                        \
+    int stride =
__bits_image->rowstride;                                       \
+    ssize_t offset0 = stride < 0
?                                              \
+    STRIDE_MULT ((-stride) >> 1, (__bits_image->height - 1) >> 1) - stride
:    \
+    STRIDE_MULT (stride,
__bits_image->height);                                 \
+    ssize_t offset1 = stride < 0
?                                              \
+    offset0 + STRIDE_MULT ((-stride) >> 1, (__bits_image->height) >> 1)
:       \
     offset0 + (offset0 >> 2)

 /* Note no trailing semicolon on the above macro; if it's there, then
@@ -182,15 +182,15 @@
  */

 #define YV12_Y(line)                                                    \
-    ((uint8_t *) ((bits) + (stride) * (line)))
+    ((uint8_t *) ((bits) + STRIDE_MULT (stride, line)))

 #define YV12_U(line)                                                    \
     ((uint8_t *) ((bits) + offset1 +                                    \
-                  ((stride) >> 1) * ((line) >> 1)))
+                  STRIDE_MULT ((stride) >> 1, (line) >> 1)))

 #define YV12_V(line)                                                    \
     ((uint8_t *) ((bits) + offset0 +                                    \
-                  ((stride) >> 1) * ((line) >> 1)))
+                  STRIDE_MULT ((stride) >> 1, (line) >> 1)))

 /* Misc. helpers */

@@ -415,56 +415,56 @@ convert_and_store_pixel (bits_image_t *        image,
     }
 }

-#define MAKE_ACCESSORS(format)                        \
-    static void                                \
-    fetch_scanline_ ## format (bits_image_t *image,            \
-                   int           x,            \
-                   int             y,            \
-                   int             width,            \
-                   uint32_t *      buffer,            \
-                   const uint32_t *mask)            \
-    {                                    \
-    uint8_t *bits =                            \
-        (uint8_t *)(image->bits + y * image->rowstride);        \
-    int i;                                \
-                                    \
-    for (i = 0; i < width; ++i)                    \
-    {                                \
-        *buffer++ =                            \
+#define MAKE_ACCESSORS(format)                             \
+    static void                                     \
+    fetch_scanline_ ## format (bits_image_t *image,                 \
+                   int           x,                 \
+                   int             y,                 \
+                   int             width,                 \
+                   uint32_t *      buffer,                 \
+                   const uint32_t *mask)                 \
+    {                                         \
+    uint8_t *bits =                                 \
+        (uint8_t *)(image->bits + STRIDE_MULT (y, image->rowstride));     \
+    int i;                                     \
+                                         \
+    for (i = 0; i < width; ++i)                         \
+    {                                     \
+        *buffer++ =                                 \
         fetch_and_convert_pixel (image, bits, x + i, PIXMAN_ ## format); \
-    }                                \
-    }                                    \
-                                    \
-    static void                                \
-    store_scanline_ ## format (bits_image_t *  image,            \
-                   int             x,            \
-                   int             y,            \
-                   int             width,            \
-                   const uint32_t *values)            \
-    {                                    \
-    uint8_t *dest =                            \
-        (uint8_t *)(image->bits + y * image->rowstride);        \
-    int i;                                \
-                                    \
-    for (i = 0; i < width; ++i)                    \
-    {                                \
-        convert_and_store_pixel (                    \
-        image, dest, i + x, PIXMAN_ ## format, values[i]);    \
-    }                                \
-    }                                    \
-                                    \
-    static uint32_t                            \
-    fetch_pixel_ ## format (bits_image_t *image,            \
-                int        offset,                \
-                int        line)                \
-    {                                    \
-    uint8_t *bits =                            \
-        (uint8_t *)(image->bits + line * image->rowstride);        \
-                                    \
-    return fetch_and_convert_pixel (                \
-        image, bits, offset, PIXMAN_ ## format);            \
-    }                                    \
-                                    \
+    }                                     \
+    }                                         \
+                                         \
+    static void                                     \
+    store_scanline_ ## format (bits_image_t *  image,                 \
+                   int             x,                 \
+                   int             y,                 \
+                   int             width,                 \
+                   const uint32_t *values)                 \
+    {                                         \
+    uint8_t *dest =                                 \
+        (uint8_t *)(image->bits + STRIDE_MULT (y, image->rowstride));     \
+    int i;                                     \
+                                         \
+    for (i = 0; i < width; ++i)                         \
+    {                                     \
+        convert_and_store_pixel (                         \
+        image, dest, i + x, PIXMAN_ ## format, values[i]);         \
+    }                                     \
+    }                                         \
+                                         \
+    static uint32_t                                 \
+    fetch_pixel_ ## format (bits_image_t *image,                 \
+                int        offset,                     \
+                int        line)                     \
+    {                                         \
+    uint8_t *bits =                                 \
+        (uint8_t *)(image->bits + STRIDE_MULT (line,
image->rowstride));     \
+                                         \
+    return fetch_and_convert_pixel (                     \
+        image, bits, offset, PIXMAN_ ## format);                 \
+    }                                         \
+                                         \
     static const void *const __dummy__ ## format

 MAKE_ACCESSORS(a8r8g8b8);
@@ -590,7 +590,7 @@ fetch_scanline_a8r8g8b8_sRGB_float (bits_image_t *
image,
                     uint32_t *      b,
                     const uint32_t *mask)
 {
-    const uint32_t *bits = image->bits + y * image->rowstride;
+    const uint32_t *bits = image->bits + STRIDE_MULT (y, image->rowstride);
     const uint32_t *pixel = bits + x;
     const uint32_t *end = pixel + width;
     argb_t *buffer = (argb_t *)b;
@@ -619,7 +619,7 @@ fetch_scanline_a2r10g10b10_float (bits_image_t *  image,
                   uint32_t *      b,
                   const uint32_t *mask)
 {
-    const uint32_t *bits = image->bits + y * image->rowstride;
+    const uint32_t *bits = image->bits + STRIDE_MULT (y, image->rowstride);
     const uint32_t *pixel = bits + x;
     const uint32_t *end = pixel + width;
     argb_t *buffer = (argb_t *)b;
@@ -650,7 +650,7 @@ fetch_scanline_x2r10g10b10_float (bits_image_t   *image,
                   uint32_t *      b,
                   const uint32_t *mask)
 {
-    const uint32_t *bits = image->bits + y * image->rowstride;
+    const uint32_t *bits = image->bits + STRIDE_MULT (y, image->rowstride);
     const uint32_t *pixel = (uint32_t *)bits + x;
     const uint32_t *end = pixel + width;
     argb_t *buffer = (argb_t *)b;
@@ -680,7 +680,7 @@ fetch_scanline_a2b10g10r10_float (bits_image_t   *image,
                   uint32_t *      b,
                   const uint32_t *mask)
 {
-    const uint32_t *bits = image->bits + y * image->rowstride;
+    const uint32_t *bits = image->bits + STRIDE_MULT (y, image->rowstride);
     const uint32_t *pixel = bits + x;
     const uint32_t *end = pixel + width;
     argb_t *buffer = (argb_t *)b;
@@ -711,7 +711,7 @@ fetch_scanline_x2b10g10r10_float (bits_image_t   *image,
                   uint32_t *      b,
                   const uint32_t *mask)
 {
-    const uint32_t *bits = image->bits + y * image->rowstride;
+    const uint32_t *bits = image->bits + STRIDE_MULT (y, image->rowstride);
     const uint32_t *pixel = (uint32_t *)bits + x;
     const uint32_t *end = pixel + width;
     argb_t *buffer = (argb_t *)b;
@@ -740,7 +740,7 @@ fetch_scanline_yuy2 (bits_image_t   *image,
                      uint32_t *      buffer,
                      const uint32_t *mask)
 {
-    const uint32_t *bits = image->bits + image->rowstride * line;
+    const uint32_t *bits = image->bits + STRIDE_MULT (image->rowstride,
line);
     int i;

     for (i = 0; i < width; i++)
@@ -810,7 +810,7 @@ fetch_pixel_x2r10g10b10_float (bits_image_t *image,
                    int       offset,
                    int           line)
 {
-    uint32_t *bits = image->bits + line * image->rowstride;
+    uint32_t *bits = image->bits + STRIDE_MULT (line, image->rowstride);
     uint32_t p = READ (image, bits + offset);
     uint64_t r = (p >> 20) & 0x3ff;
     uint64_t g = (p >> 10) & 0x3ff;
@@ -830,7 +830,7 @@ fetch_pixel_a2r10g10b10_float (bits_image_t *image,
                    int         offset,
                    int           line)
 {
-    uint32_t *bits = image->bits + line * image->rowstride;
+    uint32_t *bits = image->bits + STRIDE_MULT (line, image->rowstride);
     uint32_t p = READ (image, bits + offset);
     uint64_t a = p >> 30;
     uint64_t r = (p >> 20) & 0x3ff;
@@ -851,7 +851,7 @@ fetch_pixel_a2b10g10r10_float (bits_image_t *image,
                    int           offset,
                    int           line)
 {
-    uint32_t *bits = image->bits + line * image->rowstride;
+    uint32_t *bits = image->bits + STRIDE_MULT (line, image->rowstride);
     uint32_t p = READ (image, bits + offset);
     uint64_t a = p >> 30;
     uint64_t b = (p >> 20) & 0x3ff;
@@ -872,7 +872,7 @@ fetch_pixel_x2b10g10r10_float (bits_image_t *image,
                    int           offset,
                    int           line)
 {
-    uint32_t *bits = image->bits + line * image->rowstride;
+    uint32_t *bits = image->bits + STRIDE_MULT (line, image->rowstride);
     uint32_t p = READ (image, bits + offset);
     uint64_t b = (p >> 20) & 0x3ff;
     uint64_t g = (p >> 10) & 0x3ff;
@@ -892,7 +892,7 @@ fetch_pixel_a8r8g8b8_sRGB_float (bits_image_t *image,
                  int           offset,
                  int           line)
 {
-    uint32_t *bits = image->bits + line * image->rowstride;
+    uint32_t *bits = image->bits + STRIDE_MULT (line, image->rowstride);
     uint32_t p = READ (image, bits + offset);
     argb_t argb;

@@ -910,7 +910,7 @@ fetch_pixel_yuy2 (bits_image_t *image,
           int           offset,
           int           line)
 {
-    const uint32_t *bits = image->bits + image->rowstride * line;
+    const uint32_t *bits = image->bits + STRIDE_MULT (image->rowstride,
line);

     int16_t y, u, v;
     int32_t r, g, b;
@@ -969,7 +969,7 @@ store_scanline_a2r10g10b10_float (bits_image_t *  image,
                   int             width,
                   const uint32_t *v)
 {
-    uint32_t *bits = image->bits + image->rowstride * y;
+    uint32_t *bits = image->bits + STRIDE_MULT (image->rowstride, y);
     uint32_t *pixel = bits + x;
     argb_t *values = (argb_t *)v;
     int i;
@@ -995,7 +995,7 @@ store_scanline_x2r10g10b10_float (bits_image_t *  image,
                   int             width,
                   const uint32_t *v)
 {
-    uint32_t *bits = image->bits + image->rowstride * y;
+    uint32_t *bits = image->bits + STRIDE_MULT (image->rowstride, y);
     uint32_t *pixel = bits + x;
     argb_t *values = (argb_t *)v;
     int i;
@@ -1020,7 +1020,7 @@ store_scanline_a2b10g10r10_float (bits_image_t *
image,
                   int             width,
                   const uint32_t *v)
 {
-    uint32_t *bits = image->bits + image->rowstride * y;
+    uint32_t *bits = image->bits + STRIDE_MULT (image->rowstride, y);
     uint32_t *pixel = bits + x;
     argb_t *values = (argb_t *)v;
     int i;
@@ -1046,7 +1046,7 @@ store_scanline_x2b10g10r10_float (bits_image_t *
image,
                   int             width,
                   const uint32_t *v)
 {
-    uint32_t *bits = image->bits + image->rowstride * y;
+    uint32_t *bits = image->bits + STRIDE_MULT (image->rowstride, y);
     uint32_t *pixel = bits + x;
     argb_t *values = (argb_t *)v;
     int i;
@@ -1071,7 +1071,7 @@ store_scanline_a8r8g8b8_sRGB_float (bits_image_t *
image,
                     int             width,
                     const uint32_t *v)
 {
-    uint32_t *bits = image->bits + image->rowstride * y;
+    uint32_t *bits = image->bits + STRIDE_MULT (image->rowstride, y);
     uint32_t *pixel = bits + x;
     argb_t *values = (argb_t *)v;
     int i;
@@ -1144,7 +1144,7 @@ fetch_scanline_a8r8g8b8_32_sRGB (bits_image_t
*image,
                                  uint32_t       *buffer,
                                  const uint32_t *mask)
 {
-    const uint32_t *bits = image->bits + y * image->rowstride;
+    const uint32_t *bits = image->bits + STRIDE_MULT (y, image->rowstride);
     const uint32_t *pixel = (uint32_t *)bits + x;
     const uint32_t *end = pixel + width;
     uint32_t tmp;
@@ -1173,7 +1173,7 @@ fetch_pixel_a8r8g8b8_32_sRGB (bits_image_t *image,
                   int           offset,
                   int           line)
 {
-    uint32_t *bits = image->bits + line * image->rowstride;
+    uint32_t *bits = image->bits + STRIDE_MULT (line, image->rowstride);
     uint32_t tmp = READ (image, bits + offset);
     uint8_t a, r, g, b;

@@ -1196,7 +1196,7 @@ store_scanline_a8r8g8b8_32_sRGB (bits_image_t
*image,
                                  int             width,
                                  const uint32_t *v)
 {
-    uint32_t *bits = image->bits + image->rowstride * y;
+    uint32_t *bits = image->bits + STRIDE_MULT (image->rowstride, y);
     uint64_t *values = (uint64_t *)v;
     uint32_t *pixel = bits + x;
     uint64_t tmp;
diff --git a/pixman/pixman-arm-neon.c b/pixman/pixman-arm-neon.c
index 60e9c78..4e848a1 100644
--- a/pixman/pixman-arm-neon.c
+++ b/pixman/pixman-arm-neon.c
@@ -202,7 +202,7 @@ arm_neon_fill (pixman_implementation_t *imp,
     pixman_composite_src_n_8_asm_neon (
         width,
         height,
-        (uint8_t *)(((char *) bits) + y * byte_stride + x),
+        (uint8_t *)(((char *) bits) + STRIDE_MULT (y, byte_stride) + x),
         byte_stride,
         _xor & 0xff);
     return TRUE;
@@ -210,7 +210,7 @@ arm_neon_fill (pixman_implementation_t *imp,
     pixman_composite_src_n_0565_asm_neon (
         width,
         height,
-        (uint16_t *)(((char *) bits) + y * byte_stride + x * 2),
+        (uint16_t *)(((char *) bits) + STRIDE_MULT (y, byte_stride) + x *
2),
         byte_stride / 2,
         _xor & 0xffff);
     return TRUE;
@@ -218,7 +218,7 @@ arm_neon_fill (pixman_implementation_t *imp,
     pixman_composite_src_n_8888_asm_neon (
         width,
         height,
-        (uint32_t *)(((char *) bits) + y * byte_stride + x * 4),
+        (uint32_t *)(((char *) bits) + STRIDE_MULT (y, byte_stride) + x *
4),
         byte_stride / 4,
         _xor);
     return TRUE;
@@ -251,17 +251,17 @@ arm_neon_blt (pixman_implementation_t *imp,
     pixman_composite_src_0565_0565_asm_neon (
         width, height,
         (uint16_t *)(((char *) dst_bits) +
-        dest_y * dst_stride * 4 + dest_x * 2), dst_stride * 2,
+        STRIDE_MULT (dest_y, dst_stride) * 4 + dest_x * 2), dst_stride * 2,
         (uint16_t *)(((char *) src_bits) +
-        src_y * src_stride * 4 + src_x * 2), src_stride * 2);
+        STRIDE_MULT (src_y, src_stride) * 4 + src_x * 2), src_stride * 2);
     return TRUE;
     case 32:
     pixman_composite_src_8888_8888_asm_neon (
         width, height,
         (uint32_t *)(((char *) dst_bits) +
-        dest_y * dst_stride * 4 + dest_x * 4), dst_stride,
+        STRIDE_MULT (dest_y, dst_stride) * 4 + dest_x * 4), dst_stride,
         (uint32_t *)(((char *) src_bits) +
-        src_y * src_stride * 4 + src_x * 4), src_stride);
+        STRIDE_MULT (src_y, src_stride) * 4 + src_x * 4), src_stride);
     return TRUE;
     default:
     return FALSE;
diff --git a/pixman/pixman-arm-simd.c b/pixman/pixman-arm-simd.c
index af062e1..3e06f42 100644
--- a/pixman/pixman-arm-simd.c
+++ b/pixman/pixman-arm-simd.c
@@ -99,7 +99,7 @@ arm_simd_fill (pixman_implementation_t *imp,
     pixman_composite_src_n_8_asm_armv6 (
         width,
         height,
-        (uint8_t *)(((char *) bits) + y * byte_stride + x),
+        (uint8_t *)(((char *) bits) + STRIDE_MULT (y, byte_stride) + x),
         byte_stride,
         _xor & 0xff);
     return TRUE;
@@ -107,7 +107,7 @@ arm_simd_fill (pixman_implementation_t *imp,
     pixman_composite_src_n_0565_asm_armv6 (
         width,
         height,
-        (uint16_t *)(((char *) bits) + y * byte_stride + x * 2),
+        (uint16_t *)(((char *) bits) + STRIDE_MULT (y, byte_stride) + x *
2),
         byte_stride / 2,
         _xor & 0xffff);
     return TRUE;
@@ -115,7 +115,7 @@ arm_simd_fill (pixman_implementation_t *imp,
     pixman_composite_src_n_8888_asm_armv6 (
         width,
         height,
-        (uint32_t *)(((char *) bits) + y * byte_stride + x * 4),
+        (uint32_t *)(((char *) bits) + STRIDE_MULT (y, byte_stride) + x *
4),
         byte_stride / 4,
         _xor);
     return TRUE;
@@ -148,25 +148,25 @@ arm_simd_blt (pixman_implementation_t *imp,
         pixman_composite_src_8_8_asm_armv6 (
                 width, height,
                 (uint8_t *)(((char *) dst_bits) +
-                dest_y * dst_stride * 4 + dest_x * 1), dst_stride * 4,
+                STRIDE_MULT (dest_y, dst_stride) * 4 + dest_x * 1),
dst_stride * 4,
                 (uint8_t *)(((char *) src_bits) +
-                src_y * src_stride * 4 + src_x * 1), src_stride * 4);
+                STRIDE_MULT (src_y, src_stride) * 4 + src_x * 1),
src_stride * 4);
         return TRUE;
     case 16:
     pixman_composite_src_0565_0565_asm_armv6 (
         width, height,
         (uint16_t *)(((char *) dst_bits) +
-        dest_y * dst_stride * 4 + dest_x * 2), dst_stride * 2,
+        STRIDE_MULT (dest_y, dst_stride) * 4 + dest_x * 2), dst_stride * 2,
         (uint16_t *)(((char *) src_bits) +
-        src_y * src_stride * 4 + src_x * 2), src_stride * 2);
+        STRIDE_MULT (src_y, src_stride) * 4 + src_x * 2), src_stride * 2);
     return TRUE;
     case 32:
     pixman_composite_src_8888_8888_asm_armv6 (
         width, height,
         (uint32_t *)(((char *) dst_bits) +
-        dest_y * dst_stride * 4 + dest_x * 4), dst_stride,
+        STRIDE_MULT (dest_y, dst_stride) * 4 + dest_x * 4), dst_stride,
         (uint32_t *)(((char *) src_bits) +
-        src_y * src_stride * 4 + src_x * 4), src_stride);
+        STRIDE_MULT (src_y, src_stride) * 4 + src_x * 4), src_stride);
     return TRUE;
     default:
     return FALSE;
diff --git a/pixman/pixman-bits-image.c b/pixman/pixman-bits-image.c
index f9121a3..ab0b74e 100644
--- a/pixman/pixman-bits-image.c
+++ b/pixman/pixman-bits-image.c
@@ -926,7 +926,7 @@ create_bits (pixman_format_code_t format,
     if (_pixman_multiply_overflows_size (height, stride))
     return NULL;

-    buf_size = height * stride;
+    buf_size = STRIDE_MULT (height, stride);

     if (rowstride_bytes)
     *rowstride_bytes = stride;
diff --git a/pixman/pixman-edge.c b/pixman/pixman-edge.c
index ad6dfc4..556247f 100644
--- a/pixman/pixman-edge.c
+++ b/pixman/pixman-edge.c
@@ -167,7 +167,7 @@ rasterize_edges_8 (pixman_image_t *image,
     int stride = (image)->bits.rowstride;
     int width = (image)->bits.width;

-    line = buf + pixman_fixed_to_int (y) * stride;
+    line = buf + STRIDE_MULT (pixman_fixed_to_int (y), stride);

     for (;;)
     {
diff --git a/pixman/pixman-fast-path.c b/pixman/pixman-fast-path.c
index b06d1b2..5569c7b 100644
--- a/pixman/pixman-fast-path.c
+++ b/pixman/pixman-fast-path.c
@@ -1170,8 +1170,8 @@ fast_composite_src_memcpy (pixman_implementation_t
*imp,
     src_stride = src_image->bits.rowstride * 4;
     dst_stride = dest_image->bits.rowstride * 4;

-    src = (uint8_t *)src_image->bits.bits + src_y * src_stride + src_x *
bpp;
-    dst = (uint8_t *)dest_image->bits.bits + dest_y * dst_stride + dest_x
* bpp;
+    src = (uint8_t *)src_image->bits.bits + STRIDE_MULT (src_y,
src_stride) + src_x * bpp;
+    dst = (uint8_t *)dest_image->bits.bits + STRIDE_MULT (dest_y,
dst_stride) + dest_x * bpp;

     while (height--)
     {
@@ -1517,7 +1517,7 @@ fast_composite_scaled_nearest
(pixman_implementation_t *imp,
     {
         int w = width;

-        uint32_t *src = src_line + y * src_stride;
+        uint32_t *src = src_line + STRIDE_MULT (y, src_stride);

         while (w >= 2)
         {
@@ -1582,7 +1582,7 @@ blt_rotated_90_trivial_##suffix (pix_type
*dst,                         \
     for (y = 0; y < h;
y++)                                                   \

{                                                                         \
     const pix_type *s = src + (h - y - 1);                                \
-    pix_type *d = dst + dst_stride * y;                                   \
+    pix_type *d = dst + STRIDE_MULT (dst_stride, y);                      \
     for (x = 0; x < w; x++)                                               \
     {                                                                     \
         *d++ = *s;                                                        \
@@ -1602,8 +1602,8 @@ blt_rotated_270_trivial_##suffix (pix_type
*dst,                        \
     int x,
y;                                                                 \
     for (y = 0; y < h;
y++)                                                   \

{                                                                         \
-    const pix_type *s = src + src_stride * (w - 1) + y;                   \
-    pix_type *d = dst + dst_stride * y;                                   \
+    const pix_type *s = src + STRIDE_MULT (src_stride, (w - 1)) + y;      \
+    pix_type *d = dst + STRIDE_MULT (dst_stride, y);                      \
     for (x = 0; x < w; x++)                                               \
     {                                                                     \
         *d++ = *s;                                                        \
@@ -1648,7 +1648,7 @@ blt_rotated_90_##suffix (pix_type
*dst,                                 \
         H);                                                               \
                                                                           \
     dst += leading_pixels;                                                \
-    src += leading_pixels * src_stride;                                   \
+    src += STRIDE_MULT (leading_pixels, src_stride);                      \
     W -= leading_pixels;                                                  \

}                                                                         \

\
@@ -1667,7 +1667,7 @@ blt_rotated_90_##suffix (pix_type
*dst,                                 \
     blt_rotated_90_trivial_##suffix (                                     \
         dst + x,                                                          \
         dst_stride,                                                       \
-        src + src_stride * x,                                             \
+        src + STRIDE_MULT (src_stride, x),                                \
         src_stride,                                                       \
         TILE_SIZE,                                                        \
         H);                                                               \
@@ -1679,7 +1679,7 @@ blt_rotated_90_##suffix (pix_type
*dst,                                 \
     blt_rotated_90_trivial_##suffix (                                     \
         dst + W,                                                          \
         dst_stride,                                                       \
-        src + W * src_stride,                                             \
+        src + STRIDE_MULT (W, src_stride),                                \
         src_stride,                                                       \
         trailing_pixels,                                                  \
         H);                                                               \
@@ -1716,7 +1716,7 @@ blt_rotated_270_##suffix (pix_type
*dst,                                \
     blt_rotated_270_trivial_##suffix (                                    \
         dst,                                                              \
         dst_stride,                                                       \
-        src + src_stride * (W - leading_pixels),                          \
+        src + STRIDE_MULT (src_stride, (W - leading_pixels)),             \
         src_stride,                                                       \
         leading_pixels,                                                   \
         H);                                                               \
@@ -1732,7 +1732,7 @@ blt_rotated_270_##suffix (pix_type
*dst,                                \
     if (trailing_pixels > W)                                              \
         trailing_pixels = W;                                              \
     W -= trailing_pixels;                                                 \
-    src += trailing_pixels * src_stride;                                  \
+    src += STRIDE_MULT (trailing_pixels, src_stride);                     \

}                                                                         \

\
     for (x = 0; x < W; x +=
TILE_SIZE)                                        \
@@ -1741,7 +1741,7 @@ blt_rotated_270_##suffix (pix_type
*dst,                                \
     blt_rotated_270_trivial_##suffix (                                    \
         dst + x,                                                          \
         dst_stride,                                                       \
-        src + src_stride * (W - x - TILE_SIZE),                           \
+        src + STRIDE_MULT (src_stride, (W - x - TILE_SIZE)),              \
         src_stride,                                                       \
         TILE_SIZE,                                                        \
         H);                                                               \
@@ -1753,7 +1753,7 @@ blt_rotated_270_##suffix (pix_type
*dst,                                \
     blt_rotated_270_trivial_##suffix (                                    \
         dst + W,                                                          \
         dst_stride,                                                       \
-        src - trailing_pixels * src_stride,                               \
+        src - STRIDE_MULT (trailing_pixels, src_stride),                  \
         src_stride,                                                       \
         trailing_pixels,                                                  \
         H);                                                               \
@@ -2029,7 +2029,7 @@ pixman_fill1 (uint32_t *bits,
               int       height,
               uint32_t  filler)
 {
-    uint32_t *dst = bits + y * stride + (x >> 5);
+    uint32_t *dst = bits + STRIDE_MULT (y, stride) + (x >> 5);
     int offs = x & 31;

     if (filler & 1)
@@ -2064,7 +2064,7 @@ pixman_fill8 (uint32_t *bits,
     uint8_t v = filler & 0xff;
     int i;

-    dst = dst + y * byte_stride + x;
+    dst = dst + STRIDE_MULT (y, byte_stride) + x;

     while (height--)
     {
@@ -2090,7 +2090,7 @@ pixman_fill16 (uint32_t *bits,
     uint16_t v = filler & 0xffff;
     int i;

-    dst = dst + y * short_stride + x;
+    dst = dst + STRIDE_MULT (y, short_stride) + x;

     while (height--)
     {
@@ -2112,7 +2112,7 @@ pixman_fill32 (uint32_t *bits,
 {
     int i;

-    bits = bits + y * stride + x;
+    bits = bits + STRIDE_MULT (y, stride) + x;

     while (height--)
     {
@@ -2279,7 +2279,7 @@ static void
 fetch_horizontal (bits_image_t *image, line_t *line,
           int y, pixman_fixed_t x, pixman_fixed_t ux, int n)
 {
-    uint32_t *bits = image->bits + y * image->rowstride;
+    uint32_t *bits = image->bits + STRIDE_MULT (y, image->rowstride);
     int i;

     for (i = 0; i < n; ++i)
@@ -2543,7 +2543,7 @@ bits_image_fetch_bilinear_no_repeat_8888
(pixman_iter_t *iter,
     }
     else
     {
-    top_row = bits->bits + y1 * bits->rowstride;
+    top_row = bits->bits + STRIDE_MULT (y1, bits->rowstride);
     x_top = x;
     ux_top = ux;
     }
@@ -2556,7 +2556,7 @@ bits_image_fetch_bilinear_no_repeat_8888
(pixman_iter_t *iter,
     }
     else
     {
-    bottom_row = bits->bits + y2 * bits->rowstride;
+    bottom_row = bits->bits + STRIDE_MULT (y2, bits->rowstride);
     x_bottom = x;
     ux_bottom = ux;
     }
@@ -2798,7 +2798,7 @@ bits_image_fetch_separable_convolution_affine
(pixman_image_t * image,
                 repeat (repeat_mode, &rx, bits->width);
                 repeat (repeat_mode, &ry, bits->height);

-                row = (uint8_t *)bits->bits + bits->rowstride * 4 * ry;
+                row = (uint8_t *)bits->bits + STRIDE_MULT (bits->rowstride
* 4, ry);
                 pixel = convert_pixel (row, rx) | mask;
             }
             else
@@ -2809,7 +2809,7 @@ bits_image_fetch_separable_convolution_affine
(pixman_image_t * image,
                 }
                 else
                 {
-                row = (uint8_t *)bits->bits + bits->rowstride * 4 * ry;
+                row = (uint8_t *)bits->bits + STRIDE_MULT (bits->rowstride
* 4, ry);
                 pixel = convert_pixel (row, rx) | mask;
                 }
             }
@@ -2911,8 +2911,8 @@ bits_image_fetch_bilinear_affine (pixman_image_t *
image,
         repeat (repeat_mode, &x2, width);
         repeat (repeat_mode, &y2, height);

-        row1 = (uint8_t *)bits->bits + bits->rowstride * 4 * y1;
-        row2 = (uint8_t *)bits->bits + bits->rowstride * 4 * y2;
+        row1 = (uint8_t *)bits->bits + STRIDE_MULT (bits->rowstride * 4,
y1);
+        row2 = (uint8_t *)bits->bits + STRIDE_MULT (bits->rowstride * 4,
y2);

         tl = convert_pixel (row1, x1) | mask;
         tr = convert_pixel (row1, x2) | mask;
@@ -2947,7 +2947,7 @@ bits_image_fetch_bilinear_affine (pixman_image_t *
image,
         }
         else
         {
-        row1 = (uint8_t *)bits->bits + bits->rowstride * 4 * y1;
+        row1 = (uint8_t *)bits->bits + STRIDE_MULT (bits->rowstride * 4,
y1);
         row1 += bpp / 8 * x1;

         mask1 = PIXMAN_FORMAT_A (format)? 0 : 0xff000000;
@@ -2960,7 +2960,7 @@ bits_image_fetch_bilinear_affine (pixman_image_t *
image,
         }
         else
         {
-        row2 = (uint8_t *)bits->bits + bits->rowstride * 4 * y2;
+        row2 = (uint8_t *)bits->bits + STRIDE_MULT (bits->rowstride * 4,
y2);
         row2 += bpp / 8 * x1;

         mask2 = PIXMAN_FORMAT_A (format)? 0 : 0xff000000;
@@ -3058,7 +3058,7 @@ bits_image_fetch_nearest_affine (pixman_image_t *
image,
         repeat (repeat_mode, &y0, height);
         }

-        row = (uint8_t *)bits->bits + bits->rowstride * 4 * y0;
+        row = (uint8_t *)bits->bits + STRIDE_MULT (bits->rowstride * 4,
y0);

         buffer[i] = convert_pixel (row, x0) | mask;
     }
diff --git a/pixman/pixman-mips-dspr2.c b/pixman/pixman-mips-dspr2.c
index e10c9df..e6cb379 100644
--- a/pixman/pixman-mips-dspr2.c
+++ b/pixman/pixman-mips-dspr2.c
@@ -180,7 +180,7 @@ mips_dspr2_fill (pixman_implementation_t *imp,
     {
     case 16:
         stride = stride * (int) sizeof (uint32_t) / 2;
-        byte_line = (uint8_t *)(((uint16_t *)bits) + stride * y + x);
+        byte_line = (uint8_t *)(((uint16_t *)bits) + STRIDE_MULT (stride,
y) + x);
         byte_width = width * 2;
         stride *= 2;

@@ -193,7 +193,7 @@ mips_dspr2_fill (pixman_implementation_t *imp,
         return TRUE;
     case 32:
         stride = stride * (int) sizeof (uint32_t) / 4;
-        byte_line = (uint8_t *)(((uint32_t *)bits) + stride * y + x);
+        byte_line = (uint8_t *)(((uint32_t *)bits) + STRIDE_MULT (stride,
y) + x);
         byte_width = width * 4;
         stride *= 4;

@@ -237,9 +237,9 @@ mips_dspr2_blt (pixman_implementation_t *imp,
         src_stride = src_stride * (int) sizeof (uint32_t) / 2;
         dst_stride = dst_stride * (int) sizeof (uint32_t) / 2;
         src_bytes =(uint8_t *)(((uint16_t *)src_bits)
-                                          + src_stride * (src_y) +
(src_x));
+                                          + STRIDE_MULT (src_stride,
src_y) + src_x);
         dst_bytes = (uint8_t *)(((uint16_t *)dst_bits)
-                                           + dst_stride * (dest_y) +
(dest_x));
+                                           + STRIDE_MULT (dst_stride,
dest_y) + dest_x);
         byte_width = width * 2;
         src_stride *= 2;
         dst_stride *= 2;
@@ -257,9 +257,9 @@ mips_dspr2_blt (pixman_implementation_t *imp,
         src_stride = src_stride * (int) sizeof (uint32_t) / 4;
         dst_stride = dst_stride * (int) sizeof (uint32_t) / 4;
         src_bytes = (uint8_t *)(((uint32_t *)src_bits)
-                                           + src_stride * (src_y) +
(src_x));
+                                           + STRIDE_MULT (src_stride,
src_y) + src_x);
         dst_bytes = (uint8_t *)(((uint32_t *)dst_bits)
-                                           + dst_stride * (dest_y) +
(dest_x));
+                                           + STRIDE_MULT (dst_stride,
dest_y) + dest_x);
         byte_width = width * 4;
         src_stride *= 4;
         dst_stride *= 4;
diff --git a/pixman/pixman-mmx.c b/pixman/pixman-mmx.c
index a0f59ef..09ccf35 100644
--- a/pixman/pixman-mmx.c
+++ b/pixman/pixman-mmx.c
@@ -2102,7 +2102,7 @@ mmx_fill (pixman_implementation_t *imp,
     if (bpp == 8)
     {
     stride = stride * (int) sizeof (uint32_t) / 1;
-    byte_line = (uint8_t *)(((uint8_t *)bits) + stride * y + x);
+    byte_line = (uint8_t *)(((uint8_t *)bits) + STRIDE_MULT (stride, y) +
x);
     byte_width = width;
     stride *= 1;
         filler = (filler & 0xff) * 0x01010101;
@@ -2110,7 +2110,7 @@ mmx_fill (pixman_implementation_t *imp,
     else if (bpp == 16)
     {
     stride = stride * (int) sizeof (uint32_t) / 2;
-    byte_line = (uint8_t *)(((uint16_t *)bits) + stride * y + x);
+    byte_line = (uint8_t *)(((uint16_t *)bits) + STRIDE_MULT (stride, y) +
x);
     byte_width = 2 * width;
     stride *= 2;
         filler = (filler & 0xffff) * 0x00010001;
@@ -2118,7 +2118,7 @@ mmx_fill (pixman_implementation_t *imp,
     else
     {
     stride = stride * (int) sizeof (uint32_t) / 4;
-    byte_line = (uint8_t *)(((uint32_t *)bits) + stride * y + x);
+    byte_line = (uint8_t *)(((uint32_t *)bits) + STRIDE_MULT (stride, y) +
x);
     byte_width = 4 * width;
     stride *= 4;
     }
@@ -3287,8 +3287,8 @@ mmx_blt (pixman_implementation_t *imp,
     {
     src_stride = src_stride * (int) sizeof (uint32_t) / 2;
     dst_stride = dst_stride * (int) sizeof (uint32_t) / 2;
-    src_bytes = (uint8_t *)(((uint16_t *)src_bits) + src_stride * (src_y)
+ (src_x));
-    dst_bytes = (uint8_t *)(((uint16_t *)dst_bits) + dst_stride * (dest_y)
+ (dest_x));
+    src_bytes = (uint8_t *)(((uint16_t *)src_bits) + STRIDE_MULT
(src_stride, src_y) + src_x);
+    dst_bytes = (uint8_t *)(((uint16_t *)dst_bits) + STRIDE_MULT
(dst_stride, dest_y) + dest_x);
     byte_width = 2 * width;
     src_stride *= 2;
     dst_stride *= 2;
@@ -3297,8 +3297,8 @@ mmx_blt (pixman_implementation_t *imp,
     {
     src_stride = src_stride * (int) sizeof (uint32_t) / 4;
     dst_stride = dst_stride * (int) sizeof (uint32_t) / 4;
-    src_bytes = (uint8_t *)(((uint32_t *)src_bits) + src_stride * (src_y)
+ (src_x));
-    dst_bytes = (uint8_t *)(((uint32_t *)dst_bits) + dst_stride * (dest_y)
+ (dest_x));
+    src_bytes = (uint8_t *)(((uint32_t *)src_bits) + STRIDE_MULT
(src_stride, src_y) + src_x);
+    dst_bytes = (uint8_t *)(((uint32_t *)dst_bits) + STRIDE_MULT
(dst_stride, dest_y) + dest_x);
     byte_width = 4 * width;
     src_stride *= 4;
     dst_stride *= 4;
diff --git a/pixman/pixman-noop.c b/pixman/pixman-noop.c
index e598904..4ac95db 100644
--- a/pixman/pixman-noop.c
+++ b/pixman/pixman-noop.c
@@ -89,7 +89,7 @@ noop_init_direct_buffer (pixman_iter_t *iter, const
pixman_iter_info_t *info)
     pixman_image_t *image = iter->image;

     iter->buffer =
-    image->bits.bits + iter->y * image->bits.rowstride + iter->x;
+    image->bits.bits + STRIDE_MULT (iter->y, image->bits.rowstride) +
iter->x;
 }

 static void
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index 6ca13b2..275deaa 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -1148,6 +1148,8 @@ void pixman_timer_register (pixman_timer_t *timer);

 #endif /* PIXMAN_TIMERS */

+#define STRIDE_MULT(stride, height) ((ssize_t)(stride)*(height))
+
 #endif /* __ASSEMBLER__ */

 #endif /* PIXMAN_PRIVATE_H */
diff --git a/pixman/pixman-sse2.c b/pixman/pixman-sse2.c
index 42c7209..544c6bc 100644
--- a/pixman/pixman-sse2.c
+++ b/pixman/pixman-sse2.c
@@ -3337,7 +3337,7 @@ sse2_fill (pixman_implementation_t *imp,
     uint16_t w;

     stride = stride * (int) sizeof (uint32_t) / 1;
-    byte_line = (uint8_t *)(((uint8_t *)bits) + stride * y + x);
+    byte_line = (uint8_t *)(((uint8_t *)bits) + STRIDE_MULT (stride, y) +
x);
     byte_width = width;
     stride *= 1;

@@ -3348,7 +3348,7 @@ sse2_fill (pixman_implementation_t *imp,
     else if (bpp == 16)
     {
     stride = stride * (int) sizeof (uint32_t) / 2;
-    byte_line = (uint8_t *)(((uint16_t *)bits) + stride * y + x);
+    byte_line = (uint8_t *)(((uint16_t *)bits) + STRIDE_MULT (stride, y) +
x);
     byte_width = 2 * width;
     stride *= 2;

@@ -3357,7 +3357,7 @@ sse2_fill (pixman_implementation_t *imp,
     else if (bpp == 32)
     {
     stride = stride * (int) sizeof (uint32_t) / 4;
-    byte_line = (uint8_t *)(((uint32_t *)bits) + stride * y + x);
+    byte_line = (uint8_t *)(((uint32_t *)bits) + STRIDE_MULT (stride, y) +
x);
     byte_width = 4 * width;
     stride *= 4;
     }
@@ -4711,8 +4711,8 @@ sse2_blt (pixman_implementation_t *imp,
     {
     src_stride = src_stride * (int) sizeof (uint32_t) / 2;
     dst_stride = dst_stride * (int) sizeof (uint32_t) / 2;
-    src_bytes =(uint8_t *)(((uint16_t *)src_bits) + src_stride * (src_y) +
(src_x));
-    dst_bytes = (uint8_t *)(((uint16_t *)dst_bits) + dst_stride * (dest_y)
+ (dest_x));
+    src_bytes =(uint8_t *)(((uint16_t *)src_bits) + STRIDE_MULT
(src_stride, src_y) + src_x);
+    dst_bytes = (uint8_t *)(((uint16_t *)dst_bits) + STRIDE_MULT
(dst_stride, dest_y) + dest_x);
     byte_width = 2 * width;
     src_stride *= 2;
     dst_stride *= 2;
@@ -4721,8 +4721,8 @@ sse2_blt (pixman_implementation_t *imp,
     {
     src_stride = src_stride * (int) sizeof (uint32_t) / 4;
     dst_stride = dst_stride * (int) sizeof (uint32_t) / 4;
-    src_bytes = (uint8_t *)(((uint32_t *)src_bits) + src_stride * (src_y)
+ (src_x));
-    dst_bytes = (uint8_t *)(((uint32_t *)dst_bits) + dst_stride * (dest_y)
+ (dest_x));
+    src_bytes = (uint8_t *)(((uint32_t *)src_bits) + STRIDE_MULT
(src_stride, src_y) + src_x);
+    dst_bytes = (uint8_t *)(((uint32_t *)dst_bits) + STRIDE_MULT
(dst_stride, dest_y) + dest_x);
     byte_width = 4 * width;
     src_stride *= 4;
     dst_stride *= 4;
diff --git a/pixman/pixman-ssse3.c b/pixman/pixman-ssse3.c
index 680d6b9..ca2dfe8 100644
--- a/pixman/pixman-ssse3.c
+++ b/pixman/pixman-ssse3.c
@@ -53,7 +53,7 @@ static void
 ssse3_fetch_horizontal (bits_image_t *image, line_t *line,
             int y, pixman_fixed_t x, pixman_fixed_t ux, int n)
 {
-    uint32_t *bits = image->bits + y * image->rowstride;
+    uint32_t *bits = image->bits + STRIDE_MULT (y, image->rowstride);
     __m128i vx = _mm_set_epi16 (
     - (x + 1), x, - (x + 1), x,
     - (x + ux + 1), x + ux,  - (x + ux + 1), x + ux);
diff --git a/pixman/pixman-trap.c b/pixman/pixman-trap.c
index 91766fd..e55ddf0 100644
--- a/pixman/pixman-trap.c
+++ b/pixman/pixman-trap.c
@@ -304,7 +304,7 @@ dump_image (pixman_image_t *image,
     for (i = 0; i < image->bits.height; ++i)
     {
     uint8_t *line =
-        (uint8_t *)&(image->bits.bits[i * image->bits.rowstride]);
+        (uint8_t *)&(image->bits.bits[STRIDE_MULT (i,
image->bits.rowstride)]);

     for (j = 0; j < image->bits.width; ++j)
         printf ("%c", line[j] ? '#' : ' ');
diff --git a/pixman/pixman-utils.c b/pixman/pixman-utils.c
index 4a3a835..3261aa5 100644
--- a/pixman/pixman-utils.c
+++ b/pixman/pixman-utils.c
@@ -230,7 +230,7 @@ _pixman_iter_init_bits_stride (pixman_iter_t *iter,
const pixman_iter_info_t *in
     uint8_t *b = (uint8_t *)image->bits.bits;
     int s = image->bits.rowstride * 4;

-    iter->bits = b + s * iter->y + iter->x * PIXMAN_FORMAT_BPP
(info->format) / 8;
+    iter->bits = b + STRIDE_MULT (s, iter->y) + iter->x *
PIXMAN_FORMAT_BPP (info->format) / 8;
     iter->stride = s;
 }

diff --git a/test/affine-test.c b/test/affine-test.c
index 8e19023..ef733a0 100644
--- a/test/affine-test.c
+++ b/test/affine-test.c
@@ -74,21 +74,21 @@ test_composite (int      testnum,
     w = prng_rand_n (dst_width * 3 / 2 - dst_x);
     h = prng_rand_n (dst_height * 3 / 2 - dst_y);

-    srcbuf = (uint32_t *)malloc (src_stride * src_height);
-    dstbuf = (uint32_t *)malloc (dst_stride * dst_height);
+    srcbuf = (uint32_t *)malloc (STRIDE_MULT (src_stride, src_height));
+    dstbuf = (uint32_t *)malloc (STRIDE_MULT (dst_stride, dst_height));

-    prng_randmemset (srcbuf, src_stride * src_height, 0);
-    prng_randmemset (dstbuf, dst_stride * dst_height, 0);
+    prng_randmemset (srcbuf, STRIDE_MULT (src_stride, src_height), 0);
+    prng_randmemset (dstbuf, STRIDE_MULT (dst_stride, dst_height), 0);

     if (prng_rand_n (2) == 0)
     {
-    srcbuf += (src_stride / 4) * (src_height - 1);
+    srcbuf += STRIDE_MULT (src_stride / 4, (src_height - 1));
     src_stride = - src_stride;
     }

     if (prng_rand_n (2) == 0)
     {
-    dstbuf += (dst_stride / 4) * (dst_height - 1);
+    dstbuf += STRIDE_MULT (dst_stride / 4, (dst_height - 1));
     dst_stride = - dst_stride;
     }

@@ -294,10 +294,10 @@ test_composite (int      testnum,
     pixman_image_unref (dst_img);

     if (src_stride < 0)
-    srcbuf += (src_stride / 4) * (src_height - 1);
+    srcbuf += STRIDE_MULT (src_stride / 4, (src_height - 1));

     if (dst_stride < 0)
-    dstbuf += (dst_stride / 4) * (dst_height - 1);
+    dstbuf += STRIDE_MULT (dst_stride / 4, (dst_height - 1));

     free (srcbuf);
     free (dstbuf);
diff --git a/test/blitters-test.c b/test/blitters-test.c
index af94835..1b272dc 100644
--- a/test/blitters-test.c
+++ b/test/blitters-test.c
@@ -44,23 +44,23 @@ create_random_image (pixman_format_code_t
*allowed_formats,
     stride = (stride + 3) & ~3;

     /* do the allocation */
-    buf = aligned_malloc (64, stride * height);
+    buf = aligned_malloc (64, STRIDE_MULT (stride, height));

     if (prng_rand_n (4) == 0)
     {
     /* uniform distribution */
-    prng_randmemset (buf, stride * height, 0);
+    prng_randmemset (buf, STRIDE_MULT (stride, height), 0);
     }
     else
     {
     /* significantly increased probability for 0x00 and 0xFF */
-    prng_randmemset (buf, stride * height, RANDMEMSET_MORE_00_AND_FF);
+    prng_randmemset (buf, STRIDE_MULT (stride, height),
RANDMEMSET_MORE_00_AND_FF);
     }

     /* test negative stride */
     if (prng_rand_n (4) == 0)
     {
-    buf += (stride / 4) * (height - 1);
+    buf += STRIDE_MULT (stride / 4, (height - 1));
     stride = - stride;
     }

@@ -97,7 +97,7 @@ free_random_image (uint32_t initcrc,
     crc32 = compute_crc32_for_image (initcrc, img);

     if (img->bits.rowstride < 0)
-    data += img->bits.rowstride * (img->bits.height - 1);
+    data += STRIDE_MULT (img->bits.rowstride, img->bits.height - 1);

     pixman_image_unref (img);
     free (data);
@@ -244,7 +244,7 @@ test_composite (int testnum, int verbose)
     int w, h;
     pixman_op_t op;
     pixman_format_code_t src_fmt, dst_fmt, mask_fmt;
-    uint32_t *dstbuf, *srcbuf, *maskbuf;
+    uint32_t *srcbuf, *maskbuf;
     uint32_t crc32;
     int max_width, max_height, max_extra_stride;
     FLOAT_REGS_CORRUPTION_DETECTOR_START ();
@@ -291,7 +291,6 @@ test_composite (int testnum, int verbose)
     dst_height = pixman_image_get_height (dst_img);
     dst_stride = pixman_image_get_stride (dst_img);

-    dstbuf = pixman_image_get_data (dst_img);
     srcbuf = pixman_image_get_data (src_img);

     src_x = prng_rand_n (src_width);
diff --git a/test/composite-traps-test.c b/test/composite-traps-test.c
index 86a0355..33fd20f 100644
--- a/test/composite-traps-test.c
+++ b/test/composite-traps-test.c
@@ -104,11 +104,11 @@ test_composite (int      testnum,

     src_stride = (src_stride + 3) & ~3;

-    orig = bits = (uint32_t *)make_random_bytes (src_stride * src_height);
+    orig = bits = (uint32_t *)make_random_bytes (STRIDE_MULT (src_stride,
src_height));

     if (prng_rand_n (2) == 0)
     {
-        bits += (src_stride / 4) * (src_height - 1);
+        bits += STRIDE_MULT (src_stride / 4, src_height - 1);
         src_stride = - src_stride;
     }

@@ -157,11 +157,11 @@ test_composite (int      testnum,
     dst_stride = dst_width * dst_bpp + prng_rand_n (MAX_STRIDE) * dst_bpp;
     dst_stride = (dst_stride + 3) & ~3;

-    dst_bits = (uint32_t *)make_random_bytes (dst_stride * dst_height);
+    dst_bits = (uint32_t *)make_random_bytes (STRIDE_MULT (dst_stride,
dst_height));

     if (prng_rand_n (2) == 0)
     {
-        dst_bits += (dst_stride / 4) * (dst_height - 1);
+        dst_bits += STRIDE_MULT (dst_stride / 4, dst_height - 1);
         dst_stride = - dst_stride;
     }

@@ -232,7 +232,7 @@ test_composite (int      testnum,
     print_image (dst_img);

     if (dst_stride < 0)
-    dst_bits += (dst_stride / 4) * (dst_height - 1);
+    dst_bits += STRIDE_MULT (dst_stride / 4, dst_height - 1);

     fence_free (dst_bits);

diff --git a/test/glyph-test.c b/test/glyph-test.c
index 1811add..fd740ea 100644
--- a/test/glyph-test.c
+++ b/test/glyph-test.c
@@ -144,7 +144,7 @@ create_image (int max_size, const pixman_format_code_t
*formats, uint32_t flags)

     if (prng_rand_n (64) == 0)
     {
-    if (!(data = (uint32_t *)make_random_bytes (stride * height)))
+    if (!(data = (uint32_t *)make_random_bytes (STRIDE_MULT (stride,
height))))
     {
         fprintf (stderr, "Out of memory\n");
         abort ();
@@ -153,8 +153,8 @@ create_image (int max_size, const pixman_format_code_t
*formats, uint32_t flags)
     }
     else
     {
-    data = malloc (stride * height);
-    prng_randmemset (data, height * stride, 0);
+    data = malloc (STRIDE_MULT (stride, height));
+    prng_randmemset (data, STRIDE_MULT (height, stride), 0);
     destroy = destroy_malloced;
     }

diff --git a/test/oob-test.c b/test/oob-test.c
index 0d19b50..a7aa583 100644
--- a/test/oob-test.c
+++ b/test/oob-test.c
@@ -65,10 +65,10 @@ const composite_info_t info[] =
 static pixman_image_t *
 make_image (const image_info_t *info)
 {
-    char *data = malloc (info->stride * info->height);
+    char *data = malloc (STRIDE_MULT (info->stride, info->height));
     int i;

-    for (i = 0; i < info->height * info->stride; ++i)
+    for (i = 0; i < STRIDE_MULT (info->height, info->stride); ++i)
     data[i] = (i % 255) ^ (((i % 16) << 4) | (i & 0xf0));

     return pixman_image_create_bits (info->format, info->width,
info->height, (uint32_t *)data, info->stride);
diff --git a/test/pixel-test.c b/test/pixel-test.c
index 8c525d2..7c86be2 100644
--- a/test/pixel-test.c
+++ b/test/pixel-test.c
@@ -144,7 +144,7 @@ access (pixman_image_t *image, int x, int y)
     bytes_per_pixel = PIXMAN_FORMAT_BPP (image->bits.format) / 8;
     stride = image->bits.rowstride * 4;

-    location = (uint8_t *)image->bits.bits + y * stride + x *
bytes_per_pixel;
+    location = (uint8_t *)image->bits.bits + STRIDE_MULT (y, stride) + x *
bytes_per_pixel;

     if (bytes_per_pixel == 4)
         result = *(uint32_t *)location;
diff --git a/test/rotate-test.c b/test/rotate-test.c
index 18ca60d..5b8481b 100644
--- a/test/rotate-test.c
+++ b/test/rotate-test.c
@@ -71,7 +71,7 @@ make_image (void)
     stride = WIDTH * 4;
     if (prng_rand_n (2) == 0)
     {
-    bytes += (stride / 4) * (HEIGHT - 1);
+    bytes += STRIDE_MULT (stride / 4, HEIGHT - 1);
     stride = - stride;
     }

diff --git a/test/scaling-bench.c b/test/scaling-bench.c
index 365e798..d3e0753 100644
--- a/test/scaling-bench.c
+++ b/test/scaling-bench.c
@@ -48,8 +48,8 @@ main ()
     pixman_transform_t transform;
     pixman_image_t *dest;
     double t1, t2, t = -1;
-    uint32_t *dest_buf = aligned_malloc (16, dest_byte_stride *
dest_height);
-    memset (dest_buf, 0, dest_byte_stride * dest_height);
+    uint32_t *dest_buf = aligned_malloc (16, STRIDE_MULT
(dest_byte_stride, dest_height));
+    memset (dest_buf, 0, STRIDE_MULT (dest_byte_stride, dest_height));

     pixman_transform_init_scale (&transform, s, s);
     pixman_image_set_transform (src, &transform);
diff --git a/test/scaling-test.c b/test/scaling-test.c
index e2f7fa9..182539b 100644
--- a/test/scaling-test.c
+++ b/test/scaling-test.c
@@ -136,32 +136,32 @@ test_composite (int      testnum,
     w = prng_rand_n (dst_width * 3 / 2 - dst_x);
     h = prng_rand_n (dst_height * 3 / 2 - dst_y);

-    srcbuf = (uint32_t *)malloc (src_stride * src_height);
-    maskbuf = (uint32_t *)malloc (mask_stride * mask_height);
-    dstbuf = (uint32_t *)malloc (dst_stride * dst_height);
+    srcbuf = (uint32_t *)malloc (STRIDE_MULT (src_stride, src_height));
+    maskbuf = (uint32_t *)malloc (STRIDE_MULT (mask_stride, mask_height));
+    dstbuf = (uint32_t *)malloc (STRIDE_MULT (dst_stride, dst_height));

-    prng_randmemset (srcbuf, src_stride * src_height, 0);
-    prng_randmemset (maskbuf, mask_stride * mask_height, 0);
-    prng_randmemset (dstbuf, dst_stride * dst_height, 0);
+    prng_randmemset (srcbuf, STRIDE_MULT (src_stride, src_height), 0);
+    prng_randmemset (maskbuf, STRIDE_MULT (mask_stride, mask_height), 0);
+    prng_randmemset (dstbuf, STRIDE_MULT (dst_stride, dst_height), 0);

     src_fmt = get_format (src_bpp);
     dst_fmt = get_format (dst_bpp);

     if (prng_rand_n (2))
     {
-    srcbuf += (src_stride / 4) * (src_height - 1);
+    srcbuf += STRIDE_MULT (src_stride / 4, src_height - 1);
     src_stride = - src_stride;
     }

     if (prng_rand_n (2))
     {
-    maskbuf += (mask_stride / 4) * (mask_height - 1);
+    maskbuf += STRIDE_MULT (mask_stride / 4, mask_height - 1);
     mask_stride = - mask_stride;
     }

     if (prng_rand_n (2))
     {
-    dstbuf += (dst_stride / 4) * (dst_height - 1);
+    dstbuf += STRIDE_MULT (dst_stride / 4, dst_height - 1);
     dst_stride = - dst_stride;
     }

@@ -368,13 +368,13 @@ test_composite (int      testnum,
     pixman_image_unref (dst_img);

     if (src_stride < 0)
-    srcbuf += (src_stride / 4) * (src_height - 1);
+    srcbuf += STRIDE_MULT (src_stride / 4, src_height - 1);

     if (mask_stride < 0)
-    maskbuf += (mask_stride / 4) * (mask_height - 1);
+    maskbuf += STRIDE_MULT (mask_stride / 4, mask_height - 1);

     if (dst_stride < 0)
-    dstbuf += (dst_stride / 4) * (dst_height - 1);
+    dstbuf += STRIDE_MULT (dst_stride / 4, dst_height - 1);

     free (srcbuf);
     free (maskbuf);
diff --git a/test/stress-test.c b/test/stress-test.c
index 1f03c75..3581af1 100644
--- a/test/stress-test.c
+++ b/test/stress-test.c
@@ -112,7 +112,7 @@ destroy (pixman_image_t *image, void *data)
         bits = image->bits.bits;

         if (image->bits.rowstride < 0)
-        bits -= (- image->bits.rowstride * (image->bits.height - 1));
+        bits -= STRIDE_MULT (-image->bits.rowstride, image->bits.height -
1);

         fence_free (bits);
     }
@@ -293,7 +293,7 @@ create_random_bits_image (alpha_preference_t
alpha_preference)
     case 0:
     stride = width * PIXMAN_FORMAT_BPP (format) + prng_rand_n (17);
     stride = (stride + 3) & (~3);
-    bits = (uint32_t *)make_random_bytes (height * stride);
+    bits = (uint32_t *)make_random_bytes (STRIDE_MULT (height, stride));
     break;

     case 1:
@@ -304,19 +304,19 @@ create_random_bits_image (alpha_preference_t
alpha_preference)
     case 2: /* Zero-filled */
     stride = width * PIXMAN_FORMAT_BPP (format) + prng_rand_n (17);
     stride = (stride + 3) & (~3);
-    bits = fence_malloc (height * stride);
+    bits = fence_malloc (STRIDE_MULT (height, stride));
     if (!bits)
         return NULL;
-    memset (bits, 0, height * stride);
+    memset (bits, 0, STRIDE_MULT (height, stride));
     break;

     case 3: /* Filled with 0xFF */
     stride = width * PIXMAN_FORMAT_BPP (format) + prng_rand_n (17);
     stride = (stride + 3) & (~3);
-    bits = fence_malloc (height * stride);
+    bits = fence_malloc (STRIDE_MULT (height, stride));
     if (!bits)
         return NULL;
-    memset (bits, 0xff, height * stride);
+    memset (bits, 0xff, STRIDE_MULT (height, stride));
     break;

     case 4: /* bits is a bad pointer, has read/write functions */
@@ -329,10 +329,10 @@ create_random_bits_image (alpha_preference_t
alpha_preference)
     case 5: /* bits is a real pointer, has read/write functions */
     stride = width * PIXMAN_FORMAT_BPP (format) + prng_rand_n (17);
     stride = (stride + 3) & (~3);
-    bits = fence_malloc (height * stride);
+    bits = fence_malloc (STRIDE_MULT (height, stride));
     if (!bits)
         return NULL;
-    memset (bits, 0xff, height * stride);
+    memset (bits, 0xff, STRIDE_MULT (height, stride));
     read_func = real_reader;
     write_func = real_writer;
     break;
@@ -340,10 +340,10 @@ create_random_bits_image (alpha_preference_t
alpha_preference)
     case 6: /* bits is a real pointer, stride is negative */
     stride = (width * PIXMAN_FORMAT_BPP (format) + prng_rand_n (17));
     stride = (stride + 3) & (~3);
-    bits = (uint32_t *)make_random_bytes (height * stride);
+    bits = (uint32_t *)make_random_bytes (STRIDE_MULT (height, stride));
     if (!bits)
         return NULL;
-    bits += ((height - 1) * stride) / 4;
+    bits += STRIDE_MULT (height - 1, stride / 4);
     stride = - stride;
     break;
     }
diff --git a/test/utils.c b/test/utils.c
index a83fc06..bc6db30 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -152,7 +152,7 @@ compute_crc32_for_image_internal (uint32_t        crc32,

     if (stride < 0)
     {
-    data += (stride / 4) * (height - 1);
+    data += STRIDE_MULT(stride / 4, height - 1);
     stride = - stride;
     }

@@ -215,7 +215,7 @@ compute_crc32_for_image_internal (uint32_t        crc32,
     for (i = 0; i * PIXMAN_FORMAT_BPP (fmt) < 32; i++)
     mask |= mask << (i * PIXMAN_FORMAT_BPP (fmt));

-    for (i = 0; i < stride * height / 4; i++)
+    for (i = 0; i < STRIDE_MULT (stride / 4, height); i++)
     data[i] &= mask;

     /* swap endiannes in order to provide identical results on both big
@@ -223,7 +223,7 @@ compute_crc32_for_image_internal (uint32_t        crc32,
      */
     image_endian_swap (img);

-    return compute_crc32 (crc32, data, stride * height);
+    return compute_crc32 (crc32, data, STRIDE_MULT (stride, height));
 }

 uint32_t
@@ -269,7 +269,7 @@ print_image (pixman_image_t *image)
         if (j == (width * PIXMAN_FORMAT_BPP (format) + 7) / 8)
         printf ("| ");

-        printf ("%02X ", *((uint8_t *)buffer + i * stride + j));
+        printf ("%02X ", *((uint8_t *)buffer + STRIDE_MULT (i, stride) +
j));
     }
     printf ("\n");
     }
@@ -296,7 +296,7 @@ image_endian_swap (pixman_image_t *img)

     for (i = 0; i < height; i++)
     {
-    uint8_t *line_data = (uint8_t *)data + stride * i;
+    uint8_t *line_data = (uint8_t *)data + STRIDE_MULT (stride, i);

     switch (bpp)
     {
@@ -459,7 +459,7 @@ fence_free (void *data)
 #endif

 uint8_t *
-make_random_bytes (int n_bytes)
+make_random_bytes (size_t n_bytes)
 {
     uint8_t *bytes = fence_malloc (n_bytes);

@@ -516,7 +516,7 @@ write_png (pixman_image_t *image, const char *filename)
     int width = pixman_image_get_width (image);
     int height = pixman_image_get_height (image);
     int stride = width * 4;
-    uint32_t *data = malloc (height * stride);
+    uint32_t *data = malloc (STRIDE_MULT (height, stride));
     pixman_image_t *copy;
     png_struct *write_struct;
     png_info *info_struct;
diff --git a/test/utils.h b/test/utils.h
index 28b7193..37ee410 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -92,7 +92,7 @@ fence_free (void *data);

 /* Generate n_bytes random bytes in fence_malloced memory */
 uint8_t *
-make_random_bytes (int n_bytes);
+make_random_bytes (size_t n_bytes);

 /* Return current time in seconds */
 double
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/pixman/attachments/20130928/5d9f7120/attachment-0001.html>


More information about the Pixman mailing list