summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-01-06 11:40:30 +0000
committerTor Andersson <tor.andersson@artifex.com>2016-01-08 13:00:45 +0100
commit50e351e3f2b38618508fe76a379155918507ea75 (patch)
treeb19a746d791505909f62f7c335ef3c2477bed076
parent1db0393d21a9083586d5c055718807ec3d25f8fe (diff)
downloadmupdf-50e351e3f2b38618508fe76a379155918507ea75.tar.xz
Tweak lex_number to avoid (or minimise) underflow
Keeps operations in the int domain as long as possible, and only resorts to floats if required.
-rw-r--r--source/pdf/pdf-lex.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/source/pdf/pdf-lex.c b/source/pdf/pdf-lex.c
index 0a909a02..c2381e8d 100644
--- a/source/pdf/pdf-lex.c
+++ b/source/pdf/pdf-lex.c
@@ -71,6 +71,7 @@ lex_number(fz_context *ctx, fz_stream *f, pdf_lexbuf *buf, int c)
int n;
int d;
float v;
+ float fd;
/* Initially we might have +, -, . or a digit */
switch (c)
@@ -142,19 +143,21 @@ loop_after_dot:
}
underflow:
- /* Ignore any digits after here, because they are too small */
+ fd = 1 / (float)d;
+ v = (float)i + ((float)n * fd);
while (1)
{
c = fz_read_byte(ctx, f);
switch (c)
{
case RANGE_0_9:
+ fd /= 10;
+ v += (c - '0') * fd;
break;
default:
fz_unread_byte(ctx, f);
/* Fallthrough */
case EOF:
- v = (float)i + ((float)n / (float)d);
if (neg)
v = -v;
buf->f = v;