diff options
| author | Paul Eggert | 2011-07-18 14:57:37 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-18 14:57:37 -0700 |
| commit | a2271ba21087837896098f97663efaa60eab943e (patch) | |
| tree | 69175b766600cf348b87cf8f774b249e0c592315 /src | |
| parent | 18c525570121d8d3df377f85ec5b6f44fe39524a (diff) | |
| download | emacs-a2271ba21087837896098f97663efaa60eab943e.tar.gz emacs-a2271ba21087837896098f97663efaa60eab943e.zip | |
Don't assume that tab-width fits in int.
* character.h (sanitize_width): New inline function.
(SANE_TAB_WIDTH): New macro.
(ASCII_CHAR_WIDTH): Use it.
* indent.c (sane_tab_width): Remove. All uses replaced by
SANE_TAB_WIDTH (current_buffer).
* xdisp.c (init_iterator): Use SANE_TAB_WIDTH.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/character.h | 12 | ||||
| -rw-r--r-- | src/indent.c | 21 | ||||
| -rw-r--r-- | src/xdisp.c | 5 |
4 files changed, 26 insertions, 20 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c516a346a89..909bb052fea 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,13 @@ | |||
| 1 | 2011-07-18 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-07-18 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | Don't assume that tab-width fits in int. | ||
| 4 | * character.h (sanitize_width): New inline function. | ||
| 5 | (SANE_TAB_WIDTH): New macro. | ||
| 6 | (ASCII_CHAR_WIDTH): Use it. | ||
| 7 | * indent.c (sane_tab_width): Remove. All uses replaced by | ||
| 8 | SANE_TAB_WIDTH (current_buffer). | ||
| 9 | * xdisp.c (init_iterator): Use SANE_TAB_WIDTH. | ||
| 10 | |||
| 3 | * fileio.c: Integer overflow issues with file modes. | 11 | * fileio.c: Integer overflow issues with file modes. |
| 4 | (Fset_file_modes, auto_save_1): Don't assume EMACS_INT fits in int. | 12 | (Fset_file_modes, auto_save_1): Don't assume EMACS_INT fits in int. |
| 5 | 13 | ||
diff --git a/src/character.h b/src/character.h index 063b5147dc9..0c207113c1e 100644 --- a/src/character.h +++ b/src/character.h | |||
| @@ -556,6 +556,16 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 556 | } while (0) | 556 | } while (0) |
| 557 | 557 | ||
| 558 | 558 | ||
| 559 | /* Return a non-outlandish value for the tab width. */ | ||
| 560 | |||
| 561 | #define SANE_TAB_WIDTH(buf) sanitize_width (XFASTINT (BVAR (buf, tab_width))) | ||
| 562 | |||
| 563 | static inline int | ||
| 564 | sanitize_width (EMACS_INT width) | ||
| 565 | { | ||
| 566 | return 0 < width && width <= 1000 ? width : 8; | ||
| 567 | } | ||
| 568 | |||
| 559 | /* Return the width of ASCII character C. The width is measured by | 569 | /* Return the width of ASCII character C. The width is measured by |
| 560 | how many columns C will occupy on the screen when displayed in the | 570 | how many columns C will occupy on the screen when displayed in the |
| 561 | current buffer. */ | 571 | current buffer. */ |
| @@ -563,7 +573,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 563 | #define ASCII_CHAR_WIDTH(c) \ | 573 | #define ASCII_CHAR_WIDTH(c) \ |
| 564 | (c < 0x20 \ | 574 | (c < 0x20 \ |
| 565 | ? (c == '\t' \ | 575 | ? (c == '\t' \ |
| 566 | ? XFASTINT (BVAR (current_buffer, tab_width)) \ | 576 | ? SANE_TAB_WIDTH (current_buffer) \ |
| 567 | : (c == '\n' ? 0 : (NILP (BVAR (current_buffer, ctl_arrow)) ? 4 : 2))) \ | 577 | : (c == '\n' ? 0 : (NILP (BVAR (current_buffer, ctl_arrow)) ? 4 : 2))) \ |
| 568 | : (c < 0x7f \ | 578 | : (c < 0x7f \ |
| 569 | ? 1 \ | 579 | ? 1 \ |
diff --git a/src/indent.c b/src/indent.c index aaeaaf591ef..d89c7a9de03 100644 --- a/src/indent.c +++ b/src/indent.c | |||
| @@ -318,15 +318,6 @@ invalidate_current_column (void) | |||
| 318 | last_known_column_point = 0; | 318 | last_known_column_point = 0; |
| 319 | } | 319 | } |
| 320 | 320 | ||
| 321 | /* Return a non-outlandish value for the tab width. */ | ||
| 322 | |||
| 323 | static int | ||
| 324 | sane_tab_width (void) | ||
| 325 | { | ||
| 326 | EMACS_INT n = XFASTINT (BVAR (current_buffer, tab_width)); | ||
| 327 | return 0 < n && n <= 1000 ? n : 8; | ||
| 328 | } | ||
| 329 | |||
| 330 | EMACS_INT | 321 | EMACS_INT |
| 331 | current_column (void) | 322 | current_column (void) |
| 332 | { | 323 | { |
| @@ -335,7 +326,7 @@ current_column (void) | |||
| 335 | register int tab_seen; | 326 | register int tab_seen; |
| 336 | EMACS_INT post_tab; | 327 | EMACS_INT post_tab; |
| 337 | register int c; | 328 | register int c; |
| 338 | int tab_width = sane_tab_width (); | 329 | int tab_width = SANE_TAB_WIDTH (current_buffer); |
| 339 | int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); | 330 | int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); |
| 340 | register struct Lisp_Char_Table *dp = buffer_display_table (); | 331 | register struct Lisp_Char_Table *dp = buffer_display_table (); |
| 341 | 332 | ||
| @@ -515,7 +506,7 @@ check_display_width (EMACS_INT pos, EMACS_INT col, EMACS_INT *endpos) | |||
| 515 | static void | 506 | static void |
| 516 | scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol) | 507 | scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol) |
| 517 | { | 508 | { |
| 518 | int tab_width = sane_tab_width (); | 509 | int tab_width = SANE_TAB_WIDTH (current_buffer); |
| 519 | register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); | 510 | register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); |
| 520 | register struct Lisp_Char_Table *dp = buffer_display_table (); | 511 | register struct Lisp_Char_Table *dp = buffer_display_table (); |
| 521 | int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); | 512 | int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); |
| @@ -732,7 +723,7 @@ string_display_width (Lisp_Object string, Lisp_Object beg, Lisp_Object end) | |||
| 732 | register int tab_seen; | 723 | register int tab_seen; |
| 733 | int post_tab; | 724 | int post_tab; |
| 734 | register int c; | 725 | register int c; |
| 735 | int tab_width = sane_tab_width (); | 726 | int tab_width = SANE_TAB_WIDTH (current_buffer); |
| 736 | int ctl_arrow = !NILP (current_buffer->ctl_arrow); | 727 | int ctl_arrow = !NILP (current_buffer->ctl_arrow); |
| 737 | register struct Lisp_Char_Table *dp = buffer_display_table (); | 728 | register struct Lisp_Char_Table *dp = buffer_display_table (); |
| 738 | int b, e; | 729 | int b, e; |
| @@ -808,7 +799,7 @@ The return value is COLUMN. */) | |||
| 808 | { | 799 | { |
| 809 | EMACS_INT mincol; | 800 | EMACS_INT mincol; |
| 810 | register EMACS_INT fromcol; | 801 | register EMACS_INT fromcol; |
| 811 | int tab_width = sane_tab_width (); | 802 | int tab_width = SANE_TAB_WIDTH (current_buffer); |
| 812 | 803 | ||
| 813 | CHECK_NUMBER (column); | 804 | CHECK_NUMBER (column); |
| 814 | if (NILP (minimum)) | 805 | if (NILP (minimum)) |
| @@ -867,7 +858,7 @@ static EMACS_INT | |||
| 867 | position_indentation (register int pos_byte) | 858 | position_indentation (register int pos_byte) |
| 868 | { | 859 | { |
| 869 | register EMACS_INT column = 0; | 860 | register EMACS_INT column = 0; |
| 870 | int tab_width = sane_tab_width (); | 861 | int tab_width = SANE_TAB_WIDTH (current_buffer); |
| 871 | register unsigned char *p; | 862 | register unsigned char *p; |
| 872 | register unsigned char *stop; | 863 | register unsigned char *stop; |
| 873 | unsigned char *start; | 864 | unsigned char *start; |
| @@ -1116,7 +1107,7 @@ compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_ | |||
| 1116 | register EMACS_INT pos; | 1107 | register EMACS_INT pos; |
| 1117 | EMACS_INT pos_byte; | 1108 | EMACS_INT pos_byte; |
| 1118 | register int c = 0; | 1109 | register int c = 0; |
| 1119 | int tab_width = sane_tab_width (); | 1110 | int tab_width = SANE_TAB_WIDTH (current_buffer); |
| 1120 | register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); | 1111 | register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); |
| 1121 | register struct Lisp_Char_Table *dp = window_display_table (win); | 1112 | register struct Lisp_Char_Table *dp = window_display_table (win); |
| 1122 | EMACS_INT selective | 1113 | EMACS_INT selective |
diff --git a/src/xdisp.c b/src/xdisp.c index 4ea183ccc56..9d521ea7aaf 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -2478,10 +2478,7 @@ init_iterator (struct it *it, struct window *w, | |||
| 2478 | else if (INTEGERP (w->redisplay_end_trigger)) | 2478 | else if (INTEGERP (w->redisplay_end_trigger)) |
| 2479 | it->redisplay_end_trigger_charpos = XINT (w->redisplay_end_trigger); | 2479 | it->redisplay_end_trigger_charpos = XINT (w->redisplay_end_trigger); |
| 2480 | 2480 | ||
| 2481 | /* Correct bogus values of tab_width. */ | 2481 | it->tab_width = SANE_TAB_WIDTH (current_buffer); |
| 2482 | it->tab_width = XINT (BVAR (current_buffer, tab_width)); | ||
| 2483 | if (it->tab_width <= 0 || it->tab_width > 1000) | ||
| 2484 | it->tab_width = 8; | ||
| 2485 | 2482 | ||
| 2486 | /* Are lines in the display truncated? */ | 2483 | /* Are lines in the display truncated? */ |
| 2487 | if (base_face_id != DEFAULT_FACE_ID | 2484 | if (base_face_id != DEFAULT_FACE_ID |