summaryrefslogtreecommitdiff
path: root/src/character.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2012-02-03 11:24:22 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2012-02-03 11:24:22 -0800
commitdf0b2940c2ac0172d3548829913534d303f9ea45 (patch)
tree58695a4f633963199f5663a74f9aa0a82f199706 /src/character.c
parent9ff3f0fdc37a4856ef25db649b9b278ebf3683f7 (diff)
downloademacs-df0b2940c2ac0172d3548829913534d303f9ea45.tar.gz
emacs-df0b2940c2ac0172d3548829913534d303f9ea45.tar.bz2
emacs-df0b2940c2ac0172d3548829913534d303f9ea45.zip
Handle overflow when computing char display width (Bug#9496).
* character.c (char_width): Return EMACS_INT, not int. (char_width, c_string_width): Check for overflow when computing the width; this is possible now that individual characters can have unbounded width. Problem introduced by merge from Emacs 23 on 2012-01-19.
Diffstat (limited to 'src/character.c')
-rw-r--r--src/character.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/character.c b/src/character.c
index 593fbcece0b..82bc2bfef4e 100644
--- a/src/character.c
+++ b/src/character.c
@@ -311,10 +311,10 @@ If the multibyte character does not represent a byte, return -1. */)
/* Return width (columns) of C considering the buffer display table DP. */
-static int
+static EMACS_INT
char_width (int c, struct Lisp_Char_Table *dp)
{
- int width = CHAR_WIDTH (c);
+ EMACS_INT width = CHAR_WIDTH (c);
if (dp)
{
@@ -326,7 +326,12 @@ char_width (int c, struct Lisp_Char_Table *dp)
{
ch = AREF (disp, i);
if (CHARACTERP (ch))
- width += CHAR_WIDTH (XFASTINT (ch));
+ {
+ int w = CHAR_WIDTH (XFASTINT (ch));
+ if (INT_ADD_OVERFLOW (width, w))
+ string_overflow ();
+ width += w;
+ }
}
}
return width;
@@ -340,7 +345,8 @@ Tab is taken to occupy `tab-width' columns.
usage: (char-width CHAR) */)
(Lisp_Object ch)
{
- int c, width;
+ int c;
+ EMACS_INT width;
CHECK_CHARACTER (ch);
c = XINT (ch);
@@ -367,10 +373,14 @@ c_string_width (const unsigned char *str, EMACS_INT len, int precision,
{
int bytes;
int c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes);
- int thiswidth = char_width (c, dp);
+ EMACS_INT thiswidth = char_width (c, dp);
- if (precision > 0
- && (width + thiswidth > precision))
+ if (precision <= 0)
+ {
+ if (INT_ADD_OVERFLOW (width, thiswidth))
+ string_overflow ();
+ }
+ else if (precision - width < thiswidth)
{
*nchars = i;
*nbytes = i_byte;