From 71e34dd2493b41836db5a9b539ac7ab38e18ddd5 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 19 Feb 2012 18:06:50 +0100 Subject: Clamp real numbers when parsing. Instead of returning in 1.0 for underflow/overflow, return minimum value for underflow and maximum value for overflow. NaN returns 1.0. --- fitz/base_string.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'fitz') diff --git a/fitz/base_string.c b/fitz/base_string.c index dd9f8ea2..2c8877c8 100644 --- a/fitz/base_string.c +++ b/fitz/base_string.c @@ -256,10 +256,11 @@ float fz_atof(const char *s) * as we convert to a float. */ errno = 0; d = strtod(s, NULL); - if (errno == ERANGE || d > FLT_MAX || d < -FLT_MAX) { + if (errno == ERANGE || isnan(d)) { /* Return 1.0, as it's a small known value that won't cause a - * divide by 0. */ + divide by 0. */ return 1.0; } + d = CLAMP(d, -FLT_MAX, FLT_MAX); return (float)d; } -- cgit v1.2.3