From: Eli Zaretskii Date: Wed, 22 Feb 2023 12:55:05 +0000 (+0200) Subject: Avoid division by zero in get_narrowed_* functions X-Git-Tag: emacs-29.0.90~355^2~6 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ba91a76659b911f90914a61a2f2d5c0073a8890a;p=emacs.git Avoid division by zero in get_narrowed_* functions * src/xdisp.c (get_narrowed_width, get_narrowed_len): Return at least 1 as the value. (Bug#61704) --- diff --git a/src/xdisp.c b/src/xdisp.c index f5d54974b13..b64f1d35cbc 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -3498,18 +3498,18 @@ init_iterator (struct it *it, struct window *w, static int get_narrowed_width (struct window *w) { - int fact; /* In a character-only terminal, only one font size is used, so we can use a smaller factor. */ - fact = EQ (Fterminal_live_p (Qnil), Qt) ? 2 : 3; - return fact * window_body_width (w, WINDOW_BODY_IN_CANONICAL_CHARS); + int fact = EQ (Fterminal_live_p (Qnil), Qt) ? 2 : 3; + int width = window_body_width (w, WINDOW_BODY_IN_CANONICAL_CHARS); + return fact * max (1, width); } static int get_narrowed_len (struct window *w) { - return get_narrowed_width (w) * - window_body_height (w, WINDOW_BODY_IN_CANONICAL_CHARS); + int height = window_body_height (w, WINDOW_BODY_IN_CANONICAL_CHARS); + return get_narrowed_width (w) * max (1, height); } ptrdiff_t