summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1995-11-27 03:03:33 +0000
committerRichard M. Stallman <rms@gnu.org>1995-11-27 03:03:33 +0000
commit414279efa3455c2bb487e78d2d66d7904832cf2a (patch)
treedbebca12f02e13d43d4bb7d5525dd6de4cb30468
parent20c1de0bd20e9ed1f805f7d65f5eeb0938c0c6c4 (diff)
downloademacs-414279efa3455c2bb487e78d2d66d7904832cf2a.tar.gz
(decode_mode_spec): For p and P, avoid overflow with large buffer sizes.
-rw-r--r--src/xdisp.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/xdisp.c b/src/xdisp.c
index a1b5a2ea88f..86836714dcf 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -3790,7 +3790,11 @@ decode_mode_spec (w, c, spec_width, maxwidth)
return "Top";
else
{
- total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
+ if (total > 1000000)
+ /* Do it differently for a large value, to avoid overflow. */
+ total = ((pos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
+ else
+ total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total;
/* We can't normally display a 3-digit number,
so get us a 2-digit number that is close. */
if (total == 100)
@@ -3816,7 +3820,11 @@ decode_mode_spec (w, c, spec_width, maxwidth)
}
else
{
- total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
+ if (total > 1000000)
+ /* Do it differently for a large value, to avoid overflow. */
+ total = ((botpos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100);
+ else
+ total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total;
/* We can't normally display a 3-digit number,
so get us a 2-digit number that is close. */
if (total == 100)