diff options
| author | Paul Eggert | 2011-07-18 17:42:24 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-18 17:42:24 -0700 |
| commit | 5637687fead7d57f73ea9a7677d25b93fb785dc7 (patch) | |
| tree | e74204022166de1a8a17ed8860aa9197ce01428e /src | |
| parent | a2271ba21087837896098f97663efaa60eab943e (diff) | |
| download | emacs-5637687fead7d57f73ea9a7677d25b93fb785dc7.tar.gz emacs-5637687fead7d57f73ea9a7677d25b93fb785dc7.zip | |
Don't assume that stated character widths fit in int.
* character.c (Fchar_width, c_string_width, lisp_string_width):
* character.h (CHAR_WIDTH):
* indent.c (MULTIBYTE_BYTES_WIDTH):
Use sanitize_char_width to avoid undefined and/or bad behavior
with outlandish widths.
* character.h (sanitize_tab_width): Renamed from sanitize_width,
now that we have two such functions. All uses changed.
(sanitize_char_width): New inline function.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 12 | ||||
| -rw-r--r-- | src/character.c | 6 | ||||
| -rw-r--r-- | src/character.h | 16 | ||||
| -rw-r--r-- | src/indent.c | 2 |
4 files changed, 28 insertions, 8 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 909bb052fea..54ce0c8df4e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2011-07-19 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Don't assume that stated character widths fit in int. | ||
| 4 | * character.c (Fchar_width, c_string_width, lisp_string_width): | ||
| 5 | * character.h (CHAR_WIDTH): | ||
| 6 | * indent.c (MULTIBYTE_BYTES_WIDTH): | ||
| 7 | Use sanitize_char_width to avoid undefined and/or bad behavior | ||
| 8 | with outlandish widths. | ||
| 9 | * character.h (sanitize_tab_width): Renamed from sanitize_width, | ||
| 10 | now that we have two such functions. All uses changed. | ||
| 11 | (sanitize_char_width): New inline function. | ||
| 12 | |||
| 1 | 2011-07-18 Paul Eggert <eggert@cs.ucla.edu> | 13 | 2011-07-18 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 14 | ||
| 3 | Don't assume that tab-width fits in int. | 15 | Don't assume that tab-width fits in int. |
diff --git a/src/character.c b/src/character.c index 8e9b3e3775e..c2f23e0d8ec 100644 --- a/src/character.c +++ b/src/character.c | |||
| @@ -326,7 +326,7 @@ usage: (char-width CHAR) */) | |||
| 326 | disp = dp ? DISP_CHAR_VECTOR (dp, c) : Qnil; | 326 | disp = dp ? DISP_CHAR_VECTOR (dp, c) : Qnil; |
| 327 | 327 | ||
| 328 | if (VECTORP (disp)) | 328 | if (VECTORP (disp)) |
| 329 | width = ASIZE (disp); | 329 | width = sanitize_char_width (ASIZE (disp)); |
| 330 | else | 330 | else |
| 331 | width = CHAR_WIDTH (c); | 331 | width = CHAR_WIDTH (c); |
| 332 | 332 | ||
| @@ -358,7 +358,7 @@ c_string_width (const unsigned char *str, EMACS_INT len, int precision, | |||
| 358 | { | 358 | { |
| 359 | val = DISP_CHAR_VECTOR (dp, c); | 359 | val = DISP_CHAR_VECTOR (dp, c); |
| 360 | if (VECTORP (val)) | 360 | if (VECTORP (val)) |
| 361 | thiswidth = ASIZE (val); | 361 | thiswidth = sanitize_char_width (ASIZE (val)); |
| 362 | else | 362 | else |
| 363 | thiswidth = CHAR_WIDTH (c); | 363 | thiswidth = CHAR_WIDTH (c); |
| 364 | } | 364 | } |
| @@ -451,7 +451,7 @@ lisp_string_width (Lisp_Object string, EMACS_INT precision, | |||
| 451 | { | 451 | { |
| 452 | val = DISP_CHAR_VECTOR (dp, c); | 452 | val = DISP_CHAR_VECTOR (dp, c); |
| 453 | if (VECTORP (val)) | 453 | if (VECTORP (val)) |
| 454 | thiswidth = ASIZE (val); | 454 | thiswidth = sanitize_char_width (ASIZE (val)); |
| 455 | else | 455 | else |
| 456 | thiswidth = CHAR_WIDTH (c); | 456 | thiswidth = CHAR_WIDTH (c); |
| 457 | } | 457 | } |
diff --git a/src/character.h b/src/character.h index 0c207113c1e..09bcf17ab96 100644 --- a/src/character.h +++ b/src/character.h | |||
| @@ -558,10 +558,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 558 | 558 | ||
| 559 | /* Return a non-outlandish value for the tab width. */ | 559 | /* Return a non-outlandish value for the tab width. */ |
| 560 | 560 | ||
| 561 | #define SANE_TAB_WIDTH(buf) sanitize_width (XFASTINT (BVAR (buf, tab_width))) | 561 | #define SANE_TAB_WIDTH(buf) \ |
| 562 | 562 | sanitize_tab_width (XFASTINT (BVAR (buf, tab_width))) | |
| 563 | static inline int | 563 | static inline int |
| 564 | sanitize_width (EMACS_INT width) | 564 | sanitize_tab_width (EMACS_INT width) |
| 565 | { | 565 | { |
| 566 | return 0 < width && width <= 1000 ? width : 8; | 566 | return 0 < width && width <= 1000 ? width : 8; |
| 567 | } | 567 | } |
| @@ -579,6 +579,14 @@ sanitize_width (EMACS_INT width) | |||
| 579 | ? 1 \ | 579 | ? 1 \ |
| 580 | : ((NILP (BVAR (current_buffer, ctl_arrow)) ? 4 : 2)))) | 580 | : ((NILP (BVAR (current_buffer, ctl_arrow)) ? 4 : 2)))) |
| 581 | 581 | ||
| 582 | /* Return a non-outlandish value for a character width. */ | ||
| 583 | |||
| 584 | static inline int | ||
| 585 | sanitize_char_width (EMACS_INT width) | ||
| 586 | { | ||
| 587 | return 0 <= width && width <= 1000 ? width : 1000; | ||
| 588 | } | ||
| 589 | |||
| 582 | /* Return the width of character C. The width is measured by how many | 590 | /* Return the width of character C. The width is measured by how many |
| 583 | columns C will occupy on the screen when displayed in the current | 591 | columns C will occupy on the screen when displayed in the current |
| 584 | buffer. */ | 592 | buffer. */ |
| @@ -586,7 +594,7 @@ sanitize_width (EMACS_INT width) | |||
| 586 | #define CHAR_WIDTH(c) \ | 594 | #define CHAR_WIDTH(c) \ |
| 587 | (ASCII_CHAR_P (c) \ | 595 | (ASCII_CHAR_P (c) \ |
| 588 | ? ASCII_CHAR_WIDTH (c) \ | 596 | ? ASCII_CHAR_WIDTH (c) \ |
| 589 | : XINT (CHAR_TABLE_REF (Vchar_width_table, c))) | 597 | : sanitize_char_width (XINT (CHAR_TABLE_REF (Vchar_width_table, c)))) |
| 590 | 598 | ||
| 591 | /* If C is a variation selector, return the index numnber of the | 599 | /* If C is a variation selector, return the index numnber of the |
| 592 | variation selector (1..256). Otherwise, return 0. */ | 600 | variation selector (1..256). Otherwise, return 0. */ |
diff --git a/src/indent.c b/src/indent.c index d89c7a9de03..8a2117751aa 100644 --- a/src/indent.c +++ b/src/indent.c | |||
| @@ -284,7 +284,7 @@ skip_invisible (EMACS_INT pos, EMACS_INT *next_boundary_p, EMACS_INT to, Lisp_Ob | |||
| 284 | else \ | 284 | else \ |
| 285 | { \ | 285 | { \ |
| 286 | if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, ch))) \ | 286 | if (dp != 0 && VECTORP (DISP_CHAR_VECTOR (dp, ch))) \ |
| 287 | width = ASIZE (DISP_CHAR_VECTOR (dp, ch)); \ | 287 | width = sanitize_char_width (ASIZE (DISP_CHAR_VECTOR (dp, ch))); \ |
| 288 | else \ | 288 | else \ |
| 289 | width = CHAR_WIDTH (ch); \ | 289 | width = CHAR_WIDTH (ch); \ |
| 290 | } \ | 290 | } \ |