diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/indent.c | 46 |
2 files changed, 33 insertions, 19 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index c5931b635e8..77589f8d949 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,11 @@ | |||
| 1 | 2015-02-09 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2015-02-09 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | Check for some overflows in vertical-motion | ||
| 4 | * indent.c (window_column_x): New function. | ||
| 5 | (Fvertical_motion): Use it to protect against integer overflow | ||
| 6 | when computing column. Prefer extract_float to doing things by hand. | ||
| 7 | Avoid unnecessary casts. | ||
| 8 | |||
| 3 | * xfont.c: Minor style fixes | 9 | * xfont.c: Minor style fixes |
| 4 | (xfont_list_pattern): Reindent to 80 cols and use Emacs-style comments. | 10 | (xfont_list_pattern): Reindent to 80 cols and use Emacs-style comments. |
| 5 | Redo loop so that less indentation is needed. | 11 | Redo loop so that less indentation is needed. |
diff --git a/src/indent.c b/src/indent.c index f0aea002fd2..ce78308c95b 100644 --- a/src/indent.c +++ b/src/indent.c | |||
| @@ -1928,6 +1928,21 @@ vmotion (register ptrdiff_t from, register ptrdiff_t from_byte, | |||
| 1928 | -1, hscroll, 0, w); | 1928 | -1, hscroll, 0, w); |
| 1929 | } | 1929 | } |
| 1930 | 1930 | ||
| 1931 | /* In window W (derived from WINDOW), return x coordinate for column | ||
| 1932 | COL (derived from COLUMN). */ | ||
| 1933 | static int | ||
| 1934 | window_column_x (struct window *w, Lisp_Object window, | ||
| 1935 | double col, Lisp_Object column) | ||
| 1936 | { | ||
| 1937 | double x = col * FRAME_COLUMN_WIDTH (XFRAME (w->frame)) + 0.5; | ||
| 1938 | |||
| 1939 | /* FIXME: Should this be limited to W's dimensions? */ | ||
| 1940 | if (! (INT_MIN <= x && x <= INT_MAX)) | ||
| 1941 | args_out_of_range (window, column); | ||
| 1942 | |||
| 1943 | return x; | ||
| 1944 | } | ||
| 1945 | |||
| 1931 | DEFUN ("vertical-motion", Fvertical_motion, Svertical_motion, 1, 3, 0, | 1946 | DEFUN ("vertical-motion", Fvertical_motion, Svertical_motion, 1, 3, 0, |
| 1932 | doc: /* Move point to start of the screen line LINES lines down. | 1947 | doc: /* Move point to start of the screen line LINES lines down. |
| 1933 | If LINES is negative, this means moving up. | 1948 | If LINES is negative, this means moving up. |
| @@ -1970,15 +1985,14 @@ whether or not it is currently displayed in some window. */) | |||
| 1970 | Lisp_Object old_buffer; | 1985 | Lisp_Object old_buffer; |
| 1971 | EMACS_INT old_charpos IF_LINT (= 0), old_bytepos IF_LINT (= 0); | 1986 | EMACS_INT old_charpos IF_LINT (= 0), old_bytepos IF_LINT (= 0); |
| 1972 | struct gcpro gcpro1; | 1987 | struct gcpro gcpro1; |
| 1973 | Lisp_Object lcols = Qnil; | 1988 | Lisp_Object lcols; |
| 1974 | double cols IF_LINT (= 0); | ||
| 1975 | void *itdata = NULL; | 1989 | void *itdata = NULL; |
| 1976 | 1990 | ||
| 1977 | /* Allow LINES to be of the form (HPOS . VPOS) aka (COLUMNS . LINES). */ | 1991 | /* Allow LINES to be of the form (HPOS . VPOS) aka (COLUMNS . LINES). */ |
| 1978 | if (CONSP (lines) && (NUMBERP (XCAR (lines)))) | 1992 | bool lcols_given = CONSP (lines); |
| 1993 | if (lcols_given) | ||
| 1979 | { | 1994 | { |
| 1980 | lcols = XCAR (lines); | 1995 | lcols = XCAR (lines); |
| 1981 | cols = INTEGERP (lcols) ? (double) XINT (lcols) : XFLOAT_DATA (lcols); | ||
| 1982 | lines = XCDR (lines); | 1996 | lines = XCDR (lines); |
| 1983 | } | 1997 | } |
| 1984 | 1998 | ||
| @@ -2013,20 +2027,14 @@ whether or not it is currently displayed in some window. */) | |||
| 2013 | ptrdiff_t nlines = XINT (lines); | 2027 | ptrdiff_t nlines = XINT (lines); |
| 2014 | int vpos_init = 0; | 2028 | int vpos_init = 0; |
| 2015 | double start_col; | 2029 | double start_col; |
| 2016 | int start_x; | 2030 | int start_x IF_LINT (= 0); |
| 2017 | bool start_x_given = false; | ||
| 2018 | int to_x = -1; | 2031 | int to_x = -1; |
| 2019 | 2032 | ||
| 2020 | if (!NILP (cur_col)) | 2033 | bool start_x_given = !NILP (cur_col); |
| 2034 | if (start_x_given) | ||
| 2021 | { | 2035 | { |
| 2022 | CHECK_NUMBER_OR_FLOAT (cur_col); | 2036 | start_col = extract_float (cur_col); |
| 2023 | start_col = | 2037 | start_x = window_column_x (w, window, start_col, cur_col); |
| 2024 | INTEGERP (cur_col) | ||
| 2025 | ? (double) XINT (cur_col) | ||
| 2026 | : XFLOAT_DATA (cur_col); | ||
| 2027 | start_x = | ||
| 2028 | (int)(start_col * FRAME_COLUMN_WIDTH (XFRAME (w->frame)) + 0.5); | ||
| 2029 | start_x_given = true; | ||
| 2030 | } | 2038 | } |
| 2031 | 2039 | ||
| 2032 | itdata = bidi_shelve_cache (); | 2040 | itdata = bidi_shelve_cache (); |
| @@ -2066,7 +2074,7 @@ whether or not it is currently displayed in some window. */) | |||
| 2066 | 2074 | ||
| 2067 | if (start_x_given) | 2075 | if (start_x_given) |
| 2068 | { | 2076 | { |
| 2069 | it.hpos = (int) start_col; | 2077 | it.hpos = start_col; |
| 2070 | it.current_x = start_x; | 2078 | it.current_x = start_x; |
| 2071 | } | 2079 | } |
| 2072 | else | 2080 | else |
| @@ -2138,8 +2146,8 @@ whether or not it is currently displayed in some window. */) | |||
| 2138 | return the correct value to the caller. */ | 2146 | return the correct value to the caller. */ |
| 2139 | vpos_init = -1; | 2147 | vpos_init = -1; |
| 2140 | } | 2148 | } |
| 2141 | if (!NILP (lcols)) | 2149 | if (lcols_given) |
| 2142 | to_x = (int)(cols * FRAME_COLUMN_WIDTH (XFRAME (w->frame)) + 0.5); | 2150 | to_x = window_column_x (w, window, extract_float (lcols), lcols); |
| 2143 | if (nlines <= 0) | 2151 | if (nlines <= 0) |
| 2144 | { | 2152 | { |
| 2145 | it.vpos = vpos_init; | 2153 | it.vpos = vpos_init; |
| @@ -2185,7 +2193,7 @@ whether or not it is currently displayed in some window. */) | |||
| 2185 | /* Move to the goal column, if one was specified. If the window | 2193 | /* Move to the goal column, if one was specified. If the window |
| 2186 | was originally hscrolled, the goal column is interpreted as | 2194 | was originally hscrolled, the goal column is interpreted as |
| 2187 | an addition to the hscroll amount. */ | 2195 | an addition to the hscroll amount. */ |
| 2188 | if (!NILP (lcols)) | 2196 | if (lcols_given) |
| 2189 | move_it_in_display_line (&it, ZV, first_x + to_x, MOVE_TO_X); | 2197 | move_it_in_display_line (&it, ZV, first_x + to_x, MOVE_TO_X); |
| 2190 | 2198 | ||
| 2191 | SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it)); | 2199 | SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it)); |