Commit a2271ba2 authored by Paul Eggert's avatar Paul Eggert
Browse files

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.
parent 18c52557
2011-07-18 Paul Eggert <eggert@cs.ucla.edu>
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.
......
......@@ -556,6 +556,16 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
} 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 <http://www.gnu.org/licenses/>. */
#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 \
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment