From: Paul Eggert Date: Mon, 18 Jul 2011 21:57:37 +0000 (-0700) Subject: Don't assume that tab-width fits in int. X-Git-Tag: emacs-pretest-24.0.90~104^2~152^2~139 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a2271ba21087837896098f97663efaa60eab943e;p=emacs.git 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. --- diff --git a/src/ChangeLog b/src/ChangeLog index c516a346a89..909bb052fea 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,13 @@ 2011-07-18 Paul Eggert + 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. + * fileio.c: Integer overflow issues with file modes. (Fset_file_modes, auto_save_1): Don't assume EMACS_INT fits in int. 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 . */ } while (0) +/* Return a non-outlandish value for the tab width. */ + +#define SANE_TAB_WIDTH(buf) sanitize_width (XFASTINT (BVAR (buf, tab_width))) + +static inline int +sanitize_width (EMACS_INT width) +{ + return 0 < width && width <= 1000 ? width : 8; +} + /* Return the width of ASCII character C. The width is measured by how many columns C will occupy on the screen when displayed in the current buffer. */ @@ -563,7 +573,7 @@ along with GNU Emacs. If not, see . */ #define ASCII_CHAR_WIDTH(c) \ (c < 0x20 \ ? (c == '\t' \ - ? XFASTINT (BVAR (current_buffer, tab_width)) \ + ? SANE_TAB_WIDTH (current_buffer) \ : (c == '\n' ? 0 : (NILP (BVAR (current_buffer, ctl_arrow)) ? 4 : 2))) \ : (c < 0x7f \ ? 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) last_known_column_point = 0; } -/* Return a non-outlandish value for the tab width. */ - -static int -sane_tab_width (void) -{ - EMACS_INT n = XFASTINT (BVAR (current_buffer, tab_width)); - return 0 < n && n <= 1000 ? n : 8; -} - EMACS_INT current_column (void) { @@ -335,7 +326,7 @@ current_column (void) register int tab_seen; EMACS_INT post_tab; register int c; - int tab_width = sane_tab_width (); + int tab_width = SANE_TAB_WIDTH (current_buffer); int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); register struct Lisp_Char_Table *dp = buffer_display_table (); @@ -515,7 +506,7 @@ check_display_width (EMACS_INT pos, EMACS_INT col, EMACS_INT *endpos) static void scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol) { - int tab_width = sane_tab_width (); + int tab_width = SANE_TAB_WIDTH (current_buffer); register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); register struct Lisp_Char_Table *dp = buffer_display_table (); 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) register int tab_seen; int post_tab; register int c; - int tab_width = sane_tab_width (); + int tab_width = SANE_TAB_WIDTH (current_buffer); int ctl_arrow = !NILP (current_buffer->ctl_arrow); register struct Lisp_Char_Table *dp = buffer_display_table (); int b, e; @@ -808,7 +799,7 @@ The return value is COLUMN. */) { EMACS_INT mincol; register EMACS_INT fromcol; - int tab_width = sane_tab_width (); + int tab_width = SANE_TAB_WIDTH (current_buffer); CHECK_NUMBER (column); if (NILP (minimum)) @@ -867,7 +858,7 @@ static EMACS_INT position_indentation (register int pos_byte) { register EMACS_INT column = 0; - int tab_width = sane_tab_width (); + int tab_width = SANE_TAB_WIDTH (current_buffer); register unsigned char *p; register unsigned char *stop; unsigned char *start; @@ -1116,7 +1107,7 @@ compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_ register EMACS_INT pos; EMACS_INT pos_byte; register int c = 0; - int tab_width = sane_tab_width (); + int tab_width = SANE_TAB_WIDTH (current_buffer); register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); register struct Lisp_Char_Table *dp = window_display_table (win); 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, else if (INTEGERP (w->redisplay_end_trigger)) it->redisplay_end_trigger_charpos = XINT (w->redisplay_end_trigger); - /* Correct bogus values of tab_width. */ - it->tab_width = XINT (BVAR (current_buffer, tab_width)); - if (it->tab_width <= 0 || it->tab_width > 1000) - it->tab_width = 8; + it->tab_width = SANE_TAB_WIDTH (current_buffer); /* Are lines in the display truncated? */ if (base_face_id != DEFAULT_FACE_ID