ref: fc70233e629c5a83b20e72086e6c5e4d038982bd
parent: fa087c2d6c9ba703912ff571842c28d4cd064713
author: Ali Gholami Rudi <ali@rudi.ir>
date: Mon May 6 08:53:37 EDT 2013
eval: prevent overflow for numbers with large fractional part
--- a/eval.c
+++ b/eval.c
@@ -45,9 +45,13 @@
mag *= 10;
n = n * 10 + *s++ - '0';
}
+ if (mag > MAXFRAC) {
+ n /= mag / MAXFRAC;
+ mag /= mag / MAXFRAC;
+ }
n = readunit(*s && strchr(SCHAR, *s) ? *s++ : defunit, n);
*_s = s;
- return n / (mag > 0 ? mag : 1); /* this may overflow */
+ return n / (mag > 0 ? mag : 1);
}
static int evaljmp(char **s, int c)
--- a/xroff.h
+++ b/xroff.h
@@ -22,6 +22,7 @@
#define NIES 128 /* number of nested .ie commands */
#define NTABS 16 /* number of tab stops */
#define NFIELDS 32 /* number of fields */
+#define MAXFRAC 100000 /* maximum value of the fractional part */
/* escape sequences */
#define ESC_Q "bCDhHlLNoSvwxX" /* quoted escape sequences */