Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix float-to-int conversion to handle recent versions of clang.

Recent versions of clang are much more aggressive in exploiting undefined
behavior. Given MaxInt cannot be encoded as float, the compiler would miscompile
the macro and produce a negative number.
  • Loading branch information...
commit 898dfba28d686c78561ef666be8aac67bfc9a9ee 1 parent 64c5df8
Rodrigo Kumpera authored

Showing 1 changed file with 1 addition and 1 deletion. Show diff stats Hide diff stats

  1. 2  src/general-private.h
2  src/general-private.h
@@ -60,7 +60,7 @@
60 60
 #define gdip_near_one(value)		((value >= 0.9999f) && (value <= 1.0001f))
61 61
 
62 62
 /* avoid integer overflows when int/float/int conversion are used (see #79643) */
63  
-#define SAFE_FLOAT_TO_UINT32(value)	((value < 0) ? 0 : (value >= G_MAXINT32) ? G_MAXINT32 : value)
  63
+#define SAFE_FLOAT_TO_UINT32(value)    ((value < 0) ? 0 : (value >= G_MAXINT32) ? G_MAXINT32 : (((int)value) < 0 ? G_MAXINT32 : (int)value))
64 64
 
65 65
 /* avoid fp division and multiplication that would return the same number */
66 66
 #define OPTIMIZE_CONVERSION(g)		((g->type != gtPostScript) && ((g->page_unit == UnitPixel) || (g->page_unit == UnitWorld)))

0 notes on commit 898dfba

Please sign in to comment.
Something went wrong with that request. Please try again.