← Back to team overview

kicad-developers team mailing list archive

[PATCH 6/8] Use ptrdiff_t in potrace instead of ssize_t

 

This is backported from potrace 1.13.
---
 potrace/bitmap.h    | 15 ++++++++-------
 potrace/greymap.cpp |  2 +-
 potrace/greymap.h   |  3 ++-
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/potrace/bitmap.h b/potrace/bitmap.h
index 605aa31..059fb2b 100644
--- a/potrace/bitmap.h
+++ b/potrace/bitmap.h
@@ -7,6 +7,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <stddef.h>
 #include <errno.h>
 
 /* The bitmap type is defined in potracelib.h */
@@ -28,7 +29,7 @@
 /* macros for accessing pixel at index (x,y). U* macros omit the
  *  bounds check. */
 
-#define bm_scanline( bm, y )    ( (bm)->map + (ssize_t) (y) * (ssize_t) (bm)->dy )
+#define bm_scanline( bm, y )    ( (bm)->map + (ptrdiff_t) (y) * (ptrdiff_t) (bm)->dy )
 #define bm_index( bm, x, y )    (&bm_scanline( bm, y )[(x) / BM_WORDBITS])
 #define bm_mask( x )            ( BM_HIBIT >> ( (x) & (BM_WORDBITS - 1) ) )
 #define bm_range( x, a )        ( (int) (x) >= 0 && (int) (x) < (a) )
@@ -62,7 +63,7 @@ static inline potrace_bitmap_t* bm_new( int w, int h )
 {
     potrace_bitmap_t* bm;
     int dy = w == 0 ? 0 : (w - 1) / BM_WORDBITS + 1;
-    ssize_t size = (ssize_t) dy * (ssize_t) h * (ssize_t) BM_WORDSIZE;
+    ptrdiff_t size = (ptrdiff_t) dy * (ptrdiff_t) h * (ptrdiff_t) BM_WORDSIZE;
 
     /* check for overflow error */
     if( size < 0 || size / h / dy != BM_WORDSIZE )
@@ -97,8 +98,8 @@ static inline potrace_bitmap_t* bm_new( int w, int h )
 static inline void bm_clear( potrace_bitmap_t* bm, int c )
 {
     /* Note: if the bitmap was created with bm_new, then it is
-     *  guaranteed that size will fit into the ssize_t type. */
-    ssize_t size = (ssize_t) bm->dy * (ssize_t) bm->h * (ssize_t) BM_WORDSIZE;
+     *  guaranteed that size will fit into the ptrdiff_t type. */
+    ptrdiff_t size = (ptrdiff_t) bm->dy * (ptrdiff_t) bm->h * (ptrdiff_t) BM_WORDSIZE;
 
     memset( bm->map, c ? -1 : 0, size );
 }
@@ -108,7 +109,7 @@ static inline void bm_clear( potrace_bitmap_t* bm, int c )
 static inline potrace_bitmap_t* bm_dup( const potrace_bitmap_t* bm )
 {
     potrace_bitmap_t* bm1 = bm_new( bm->w, bm->h );
-    ssize_t size = (ssize_t) bm->dy * (ssize_t) bm->h * (ssize_t) BM_WORDSIZE;
+    ptrdiff_t size = (ptrdiff_t) bm->dy * (ptrdiff_t) bm->h * (ptrdiff_t) BM_WORDSIZE;
 
     if( !bm1 )
     {
@@ -123,8 +124,8 @@ static inline potrace_bitmap_t* bm_dup( const potrace_bitmap_t* bm )
 /* invert the given bitmap. */
 static inline void bm_invert( potrace_bitmap_t* bm )
 {
-    ssize_t i;
-    ssize_t size = (ssize_t) bm->dy * (ssize_t) bm->h;
+    ptrdiff_t i;
+    ptrdiff_t size = (ptrdiff_t) bm->dy * (ptrdiff_t) bm->h;
 
     for( i = 0; i < size; i++ )
     {
diff --git a/potrace/greymap.cpp b/potrace/greymap.cpp
index fd06d87..e4a0b85 100644
--- a/potrace/greymap.cpp
+++ b/potrace/greymap.cpp
@@ -29,7 +29,7 @@ static int  gm_readbody_bmp( FILE* f, greymap_t** gmp );
 greymap_t* gm_new( int w, int h )
 {
     greymap_t* gm;
-    ssize_t size = (ssize_t) w * (ssize_t) h * (ssize_t) sizeof(signed short int);
+    ptrdiff_t size = (ptrdiff_t) w * (ptrdiff_t) h * (ptrdiff_t) sizeof(signed short int);
 
     /* check for overflow error */
     if( size < 0 || size / w / h != sizeof(signed short int) )
diff --git a/potrace/greymap.h b/potrace/greymap.h
index 000c65e..2505232 100644
--- a/potrace/greymap.h
+++ b/potrace/greymap.h
@@ -8,6 +8,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stddef.h>
 
 /* internal format for greymaps. Note: in this format, rows are
  *  ordered from bottom to top. The pixels in each row are given from
@@ -24,7 +25,7 @@ typedef struct greymap_s greymap_t;
 /* macros for accessing pixel at index (x,y). Note that the origin is
  *  in the *lower* left corner. U* macros omit the bounds check. */
 
-#define gm_index( gm, x, y )    (&(gm)->map[(x) + (y) * (ssize_t) (gm)->w])
+#define gm_index( gm, x, y )    (&(gm)->map[(x) + (y) * (ptrdiff_t) (gm)->w])
 #define gm_safe( gm, x, \
                  y )            ( (int) (x)>=0 && (int) (x)<(gm)->w && (int) (y)>=0 \
                                   && (int) (y)<(gm)->h )

Follow ups

References