summaryrefslogtreecommitdiff
path: root/fitz/base_string.c
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2011-05-31 15:49:39 +0100
committerTor Andersson <tor.andersson@artifex.com>2011-05-31 17:28:21 +0200
commit97b83d84e3d10ccd298f9c54713323a3e41ce7f3 (patch)
tree4877fbe7f4d2afff109b3bafa11bed6c013afd5b /fitz/base_string.c
parent89bf9896bd9d05500ac6494452a1b9d9cf8a67cb (diff)
downloadmupdf-97b83d84e3d10ccd298f9c54713323a3e41ce7f3.tar.xz
Fix assert in scale: see Bug 692245.
Bug 692245 gives a file that produces a runtime assert in mupdf due to an extremely large ctm offset (unrepresentable in a float). We fix our code here so that such floats are always read as 1.0. In this particular case, the exact value read doesn't seem to matter. We match acrobat. We pick 1.0 rather than 0.0 as this is less likely to provoke division by 0 errors later on.
Diffstat (limited to 'fitz/base_string.c')
-rw-r--r--fitz/base_string.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/fitz/base_string.c b/fitz/base_string.c
index 72a7a556..76748e20 100644
--- a/fitz/base_string.c
+++ b/fitz/base_string.c
@@ -245,3 +245,21 @@ runelen(int c)
char str[10];
return runetochar(str, &c);
}
+
+float fz_atof(const char *s)
+{
+ double d;
+
+ /* The errno voodoo here checks for us reading numbers that are too
+ * big to fit into a double. The checks for FLT_MAX ensure that we
+ * don't read a number that's OK as a double and then become invalid
+ * as we convert to a float. */
+ errno = 0;
+ d = strtod(s, NULL);
+ if (errno == ERANGE || d > FLT_MAX || d < -FLT_MAX) {
+ /* Return 1.0, as it's a small known value that won't cause a
+ * divide by 0. */
+ return 1.0;
+ }
+ return (float)d;
+}