From 3c7d31b921c1f532f0c2ff6b97a1cb9c93617dbf Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Mon, 27 Nov 1995 03:03:33 +0000 Subject: [PATCH] (decode_mode_spec): For p and P, avoid overflow with large buffer sizes. --- src/xdisp.c | 12 ++++++++++-- 1 file 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) -- 2.39.2