[cairo] [PATCH 0/4] RFC: Stop MSVC and MSYS from complaining

Simon Richter Simon.Richter at hogyros.de
Wed Feb 10 21:49:04 CET 2016


on Windows, the "long" and "unsigned long" data types are 32 bit wide, even
if the pointer size is 64 bit.

This patch set gets rid of a number of warnings related to pointers and
integers being converted back and forth while their size changes, by
replacing select instances of "unsigned long" with "intptr_t".

This is not meant as a final patch set, because:

 - I have no idea whether these changes are correct or exhaustive. It seems
   to work on my machine, but that's it.
 - It grows a few data structures that are probably meant to be small.
 - It uses a signed type where the original type was unsigned. "uintptr_t"
   also exists in the standard, but MSVC does not define it.

I'm fairly sure that the mempool change indeed fixes a bug -- pointer
arithmetic should really be performed using wide enough types.

I'm slightly less sure about the changes to the scaled fonts, but it
appears that one of the pointers generated from casting an integer back is
then dereferenced, so it would indeed be good to keep all the bits.
However, this is where we introduce lots of overhead.

The script surface code is not really affected, because it works the other
way 'round: an integer is stored in a pointer, then later retrieved and
cast back to integer. Because this integer is supposedly small, there is no
problem, except for some dangerously looking compiler warnings.

Last but not least, the script surface contains a check that might have an
off by one error. The integer is later on cast to uint8_t, which implies
AND 0xff (which I make explicit, because MSVC complains about losing bits
that arent' guaranteed to be zero), so 256 becomes 0. As the check
terminates the loop at 257 because it uses a greater-than comparison, this
smells a bit fishy.


Simon Richter (4):
  mempool: use wide enough type for pointer arithmetic
  scaled fonts: Use wide enough type for pointer arithmetic
  script surface: Avoid compiler warnings
  script surface: fix off by one error

 src/cairo-cache-private.h       |  2 +-
 src/cairo-hash.c                |  2 +-
 src/cairo-mempool.c             |  6 +++---
 src/cairo-scaled-font-subsets.c |  4 ++--
 src/cairo-scaled-font.c         |  4 ++--
 src/cairo-script-surface.c      | 28 +++++++++++-----------------
 src/cairo-types-private.h       |  2 +-
 7 files changed, 21 insertions(+), 27 deletions(-)


More information about the cairo mailing list