summaryrefslogtreecommitdiff
path: root/plugins/fast_float/src/fast_float_internal.h
diff options
context:
space:
mode:
authorMarti Maria <marti.maria@littlecms.com>2021-04-17 20:48:47 +0200
committerMarti Maria <marti.maria@littlecms.com>2021-04-17 20:48:47 +0200
commit31f6546c45a874450903c8635fc2d71893502056 (patch)
tree2450f349b37c4197ac09e09a73b73927c61cb87b /plugins/fast_float/src/fast_float_internal.h
parente71a11d3a6bdc1052158598978b4d6c60819bdce (diff)
downloadlcms2-31f6546c45a874450903c8635fc2d71893502056.tar.gz
add some checks for NAN and denormalized
User buffers may contain invalid float numbers
Diffstat (limited to 'plugins/fast_float/src/fast_float_internal.h')
-rw-r--r--plugins/fast_float/src/fast_float_internal.h20
1 files changed, 17 insertions, 3 deletions
diff --git a/plugins/fast_float/src/fast_float_internal.h b/plugins/fast_float/src/fast_float_internal.h
index 43de02d..f3bcddd 100644
--- a/plugins/fast_float/src/fast_float_internal.h
+++ b/plugins/fast_float/src/fast_float_internal.h
@@ -41,6 +41,21 @@
# define cmsINLINE static inline
#endif
+/// Properly define some macros to accommodate
+/// older MSVC versions.
+# if defined(_MSC_VER) && _MSC_VER <= 1700
+#include <float.h>
+#define isnan _isnan
+#define isinf(x) (!_finite((x)))
+# endif
+
+#if !defined(_MSC_VER) && (defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L)
+#if !defined(isinf)
+#define isinf(x) (!finite((x)))
+#endif
+#endif
+
+
// A fast way to convert from/to 16 <-> 8 bits
#define FROM_8_TO_16(rgb) (cmsUInt16Number) ((((cmsUInt16Number) (rgb)) << 8)|(rgb))
#define FROM_16_TO_8(rgb) (cmsUInt8Number) ((((rgb) * 65281 + 8388608) >> 24) & 0xFF)
@@ -72,11 +87,10 @@ typedef struct {
#define MAX_NODES_IN_CURVE 0x8001
-
// To prevent out of bounds indexing
cmsINLINE cmsFloat32Number fclamp(cmsFloat32Number v)
{
- return v < 0.0f ? 0.0f : (v > 1.0f ? 1.0f : v);
+ return ((v < 1.0e-9f) || isnan(v)) ? 0.0f : (v > 1.0f ? 1.0f : v);
}
// Fast floor conversion logic.
@@ -120,7 +134,7 @@ cmsINLINE cmsFloat32Number flerp(const cmsFloat32Number LutTable[], cmsFloat32Nu
cmsFloat32Number rest;
int cell0, cell1;
- if (v <= 0.0) {
+ if ((v < 1.0e-9f) || isnan(v)) {
return LutTable[0];
}
else