Merge branch 'master' of /Users/jrmuizel/bugs/colorspace/qcms into bnew

Conflicts:
	transform.c
diff --git a/iccread.c b/iccread.c
index 954b473..2bb0014 100644
--- a/iccread.c
+++ b/iccread.c
@@ -820,12 +820,12 @@
 
 static uint16_t float_to_u8Fixed8Number(float a)
 {
-	if (a > (255. + 255./256))
+	if (a > (255.f + 255.f/256))
 		return 0xffff;
-	else if (a < 0.)
+	else if (a < 0.f)
 		return 0;
 	else
-		return floor(a*256. + .5);
+		return floor(a*256.f + .5f);
 }
 
 static struct curveType *curve_from_gamma(float gamma)
@@ -1159,9 +1159,11 @@
 	be32 length_be;
 	void *data;
 
-	fread(&length_be, sizeof(length), 1, file);
+	if (fread(&length_be, 1, sizeof(length_be), file) != sizeof(length_be))
+		return BAD_VALUE_PROFILE;
+
 	length = be32_to_cpu(length_be);
-	if (length > MAX_PROFILE_SIZE)
+	if (length > MAX_PROFILE_SIZE || length < sizeof(length_be))
 		return BAD_VALUE_PROFILE;
 
 	/* allocate room for the entire profile */
diff --git a/qcmsint.h b/qcmsint.h
index 0de134b..3818f0f 100644
--- a/qcmsint.h
+++ b/qcmsint.h
@@ -226,9 +226,11 @@
 #define inline _inline
 #endif
 
+/* produces the nearest float to 'a' with a maximum error
+ * of 1/1024 which happens for large values like 0x40000040 */
 static inline float s15Fixed16Number_to_float(s15Fixed16Number a)
 {
-	return ((int32_t)a)/65536.;
+	return ((int32_t)a)/65536.f;
 }
 
 static inline s15Fixed16Number double_to_s15Fixed16Number(double v)
diff --git a/qcmstypes.h b/qcmstypes.h
index 26c138a..2d98c0c 100644
--- a/qcmstypes.h
+++ b/qcmstypes.h
@@ -25,9 +25,7 @@
 #ifdef __OS2__
 /* OS/2's stdlib typdefs uintptr_t. So we'll just include that so we don't collide */
 #include <stdlib.h>
-#elif defined(__FreeBSD__)
-/* FreeBSD typedefs uintptr_t in /usr/include/sys/types.h */
-#else
+#elif !defined(__intptr_t_defined) && !defined(_UINTPTR_T_DEFINED)
 typedef PRUptrdiff uintptr_t;
 #endif
 #endif