aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-08-29 13:06:52 -0700
committerPaul Eggert2011-08-29 13:06:52 -0700
commit1a091fbc08faa3bab85e74f7fac72a955600a8f6 (patch)
treee3f3a5700086aef93d027590c497ccac14b0e696 /src
parentc43c8a6af9f6877b97c1f9a88e361456775cb88b (diff)
parentb31b81a53a0908e16360003c0218dadba897f449 (diff)
downloademacs-1a091fbc08faa3bab85e74f7fac72a955600a8f6.tar.gz
emacs-1a091fbc08faa3bab85e74f7fac72a955600a8f6.zip
Merge from trunk.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog34
-rw-r--r--src/bidi.c13
-rw-r--r--src/ccl.c32
-rw-r--r--src/image.c30
-rw-r--r--src/makefile.w32-in1
-rw-r--r--src/term.c10
-rw-r--r--src/xdisp.c29
7 files changed, 97 insertions, 52 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index d38d2df6b8c..9f86c42d43b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -101,6 +101,40 @@
101 101
102 * xterm.h (x_check_errors): Add ATTRIBUTE_FORMAT_PRINTF. 102 * xterm.h (x_check_errors): Add ATTRIBUTE_FORMAT_PRINTF.
103 103
1042011-08-29 Paul Eggert <eggert@cs.ucla.edu>
105
106 * image.c (parse_image_spec): Check for nonnegative, not for positive,
107 when checking :margin (Bug#9390).
108 (IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR):
109 Renamed from IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR,
110 so that the name doesn't mislead. All uses changed.
111
1122011-08-28 Johan Bockgård <bojohan@gnu.org>
113
114 * term.c (init_tty) [HAVE_GPM]: Move mouse settings after
115 set_tty_hooks.
116
1172011-08-27 Eli Zaretskii <eliz@gnu.org>
118
119 * xdisp.c (move_it_to): Don't bail out early when reaching
120 position beyond to_charpos, if we are scanning backwards.
121 (move_it_vertically_backward): When DY == 0, make sure we get to
122 the first character in the line after the newline.
123
1242011-08-27 Paul Eggert <eggert@cs.ucla.edu>
125
126 * ccl.c: Improve and simplify overflow checking (Bug#9196).
127 (ccl_driver): Do not generate an out-of-range pointer.
128 (Fccl_execute_on_string): Remove unnecessary check for
129 integer overflow, noted by Stefan Monnier in
130 <http://lists.gnu.org/archive/html/emacs-devel/2011-08/msg00979.html>.
131 Remove a FIXME that didn't need fixing.
132 Simplify the newly-introduced buffer reallocation code.
133
1342011-08-27 Juanma Barranquero <lekktu@gmail.com>
135
136 * makefile.w32-in ($(BLD)/alloc.$(O)): Depend on lib/verify.h.
137
1042011-08-26 Paul Eggert <eggert@cs.ucla.edu> 1382011-08-26 Paul Eggert <eggert@cs.ucla.edu>
105 139
106 Integer and memory overflow issues (Bug#9196). 140 Integer and memory overflow issues (Bug#9196).
diff --git a/src/bidi.c b/src/bidi.c
index 564d985f890..bb29647ea88 100644
--- a/src/bidi.c
+++ b/src/bidi.c
@@ -910,16 +910,15 @@ bidi_char_at_pos (EMACS_INT bytepos, const unsigned char *s, int unibyte)
910 covered characters as a single character, either u+2029 or u+FFFC, 910 covered characters as a single character, either u+2029 or u+FFFC,
911 and return their combined length in CH_LEN and NCHARS. DISP_POS 911 and return their combined length in CH_LEN and NCHARS. DISP_POS
912 specifies the character position of the next display string, or -1 912 specifies the character position of the next display string, or -1
913 if not yet computed. DISP_PROP non-zero means that there's really 913 if not yet computed. When the next character is at or beyond that
914 position, the function updates DISP_POS with the position of the
915 next display string. DISP_PROP non-zero means that there's really
914 a display string at DISP_POS, as opposed to when we searched till 916 a display string at DISP_POS, as opposed to when we searched till
915 DISP_POS without finding one. If DISP_PROP is 2, it means the 917 DISP_POS without finding one. If DISP_PROP is 2, it means the
916 display spec is of the form `(space ...)', which is replaced with 918 display spec is of the form `(space ...)', which is replaced with
917 u+2029 to handle it as a paragraph separator. When the next 919 u+2029 to handle it as a paragraph separator. STRING->s is the C
918 character is at or beyond that position, the function updates 920 string to iterate, or NULL if iterating over a buffer or a Lisp
919 DISP_POS with the position of the next display string. STRING->s 921 string; in the latter case, STRING->lstring is the Lisp string. */
920 is the C string to iterate, or NULL if iterating over a buffer or a
921 Lisp string; in the latter case, STRING->lstring is the Lisp
922 string. */
923static inline int 922static inline int
924bidi_fetch_char (EMACS_INT bytepos, EMACS_INT charpos, EMACS_INT *disp_pos, 923bidi_fetch_char (EMACS_INT bytepos, EMACS_INT charpos, EMACS_INT *disp_pos,
925 int *disp_prop, struct bidi_string_data *string, 924 int *disp_prop, struct bidi_string_data *string,
diff --git a/src/ccl.c b/src/ccl.c
index dc0adae6877..b28a284f70a 100644
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -1770,7 +1770,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
1770 } 1770 }
1771 1771
1772 msglen = strlen (msg); 1772 msglen = strlen (msg);
1773 if (dst + msglen <= dst_end) 1773 if (msglen <= dst_end - dst)
1774 { 1774 {
1775 for (i = 0; i < msglen; i++) 1775 for (i = 0; i < msglen; i++)
1776 *dst++ = msg[i]; 1776 *dst++ = msg[i];
@@ -2127,37 +2127,25 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
2127 src_size = j; 2127 src_size = j;
2128 while (1) 2128 while (1)
2129 { 2129 {
2130 int max_expansion = NILP (unibyte_p) ? MAX_MULTIBYTE_LENGTH : 1;
2131 ptrdiff_t offset, shortfall;
2130 ccl_driver (&ccl, src, destination, src_size, CCL_EXECUTE_BUF_SIZE, 2132 ccl_driver (&ccl, src, destination, src_size, CCL_EXECUTE_BUF_SIZE,
2131 Qnil); 2133 Qnil);
2132 produced_chars += ccl.produced; 2134 produced_chars += ccl.produced;
2135 offset = outp - outbuf;
2136 shortfall = ccl.produced * max_expansion - (outbufsize - offset);
2137 if (0 < shortfall)
2138 {
2139 outbuf = xpalloc (outbuf, &outbufsize, shortfall, -1, 1);
2140 outp = outbuf + offset;
2141 }
2133 if (NILP (unibyte_p)) 2142 if (NILP (unibyte_p))
2134 { 2143 {
2135 /* FIXME: Surely this should be buf_magnification instead.
2136 MAX_MULTIBYTE_LENGTH overestimates the storage needed. */
2137 int magnification = MAX_MULTIBYTE_LENGTH;
2138
2139 ptrdiff_t offset = outp - outbuf;
2140 ptrdiff_t shortfall;
2141 if (INT_MULTIPLY_OVERFLOW (ccl.produced, magnification))
2142 memory_full (SIZE_MAX);
2143 shortfall = ccl.produced * magnification - (outbufsize - offset);
2144 if (0 < shortfall)
2145 {
2146 outbuf = xpalloc (outbuf, &outbufsize, shortfall, -1, 1);
2147 outp = outbuf + offset;
2148 }
2149 for (j = 0; j < ccl.produced; j++) 2144 for (j = 0; j < ccl.produced; j++)
2150 CHAR_STRING_ADVANCE (destination[j], outp); 2145 CHAR_STRING_ADVANCE (destination[j], outp);
2151 } 2146 }
2152 else 2147 else
2153 { 2148 {
2154 ptrdiff_t offset = outp - outbuf;
2155 ptrdiff_t shortfall = ccl.produced - (outbufsize - offset);
2156 if (0 < shortfall)
2157 {
2158 outbuf = xpalloc (outbuf, &outbufsize, shortfall, -1, 1);
2159 outp = outbuf + offset;
2160 }
2161 for (j = 0; j < ccl.produced; j++) 2149 for (j = 0; j < ccl.produced; j++)
2162 *outp++ = destination[j]; 2150 *outp++ = destination[j];
2163 } 2151 }
diff --git a/src/image.c b/src/image.c
index d0d28bea582..d6bfc4050ca 100644
--- a/src/image.c
+++ b/src/image.c
@@ -691,7 +691,7 @@ enum image_value_type
691 IMAGE_STRING_OR_NIL_VALUE, 691 IMAGE_STRING_OR_NIL_VALUE,
692 IMAGE_SYMBOL_VALUE, 692 IMAGE_SYMBOL_VALUE,
693 IMAGE_POSITIVE_INTEGER_VALUE, 693 IMAGE_POSITIVE_INTEGER_VALUE,
694 IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 694 IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR,
695 IMAGE_NON_NEGATIVE_INTEGER_VALUE, 695 IMAGE_NON_NEGATIVE_INTEGER_VALUE,
696 IMAGE_ASCENT_VALUE, 696 IMAGE_ASCENT_VALUE,
697 IMAGE_INTEGER_VALUE, 697 IMAGE_INTEGER_VALUE,
@@ -798,12 +798,12 @@ parse_image_spec (Lisp_Object spec, struct image_keyword *keywords,
798 return 0; 798 return 0;
799 break; 799 break;
800 800
801 case IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR: 801 case IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR:
802 if (RANGED_INTEGERP (1, value, INT_MAX)) 802 if (RANGED_INTEGERP (0, value, INT_MAX))
803 break; 803 break;
804 if (CONSP (value) 804 if (CONSP (value)
805 && RANGED_INTEGERP (1, XCAR (value), INT_MAX) 805 && RANGED_INTEGERP (0, XCAR (value), INT_MAX)
806 && RANGED_INTEGERP (1, XCDR (value), INT_MAX)) 806 && RANGED_INTEGERP (0, XCDR (value), INT_MAX))
807 break; 807 break;
808 return 0; 808 return 0;
809 809
@@ -2256,7 +2256,7 @@ static const struct image_keyword xbm_format[XBM_LAST] =
2256 {":foreground", IMAGE_STRING_OR_NIL_VALUE, 0}, 2256 {":foreground", IMAGE_STRING_OR_NIL_VALUE, 0},
2257 {":background", IMAGE_STRING_OR_NIL_VALUE, 0}, 2257 {":background", IMAGE_STRING_OR_NIL_VALUE, 0},
2258 {":ascent", IMAGE_ASCENT_VALUE, 0}, 2258 {":ascent", IMAGE_ASCENT_VALUE, 0},
2259 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 2259 {":margin", IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR, 0},
2260 {":relief", IMAGE_INTEGER_VALUE, 0}, 2260 {":relief", IMAGE_INTEGER_VALUE, 0},
2261 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 2261 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
2262 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 2262 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
@@ -3051,7 +3051,7 @@ static const struct image_keyword xpm_format[XPM_LAST] =
3051 {":file", IMAGE_STRING_VALUE, 0}, 3051 {":file", IMAGE_STRING_VALUE, 0},
3052 {":data", IMAGE_STRING_VALUE, 0}, 3052 {":data", IMAGE_STRING_VALUE, 0},
3053 {":ascent", IMAGE_ASCENT_VALUE, 0}, 3053 {":ascent", IMAGE_ASCENT_VALUE, 0},
3054 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 3054 {":margin", IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR, 0},
3055 {":relief", IMAGE_INTEGER_VALUE, 0}, 3055 {":relief", IMAGE_INTEGER_VALUE, 0},
3056 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 3056 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
3057 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 3057 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
@@ -4980,7 +4980,7 @@ static const struct image_keyword pbm_format[PBM_LAST] =
4980 {":file", IMAGE_STRING_VALUE, 0}, 4980 {":file", IMAGE_STRING_VALUE, 0},
4981 {":data", IMAGE_STRING_VALUE, 0}, 4981 {":data", IMAGE_STRING_VALUE, 0},
4982 {":ascent", IMAGE_ASCENT_VALUE, 0}, 4982 {":ascent", IMAGE_ASCENT_VALUE, 0},
4983 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 4983 {":margin", IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR, 0},
4984 {":relief", IMAGE_INTEGER_VALUE, 0}, 4984 {":relief", IMAGE_INTEGER_VALUE, 0},
4985 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 4985 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
4986 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 4986 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
@@ -5395,7 +5395,7 @@ static const struct image_keyword png_format[PNG_LAST] =
5395 {":data", IMAGE_STRING_VALUE, 0}, 5395 {":data", IMAGE_STRING_VALUE, 0},
5396 {":file", IMAGE_STRING_VALUE, 0}, 5396 {":file", IMAGE_STRING_VALUE, 0},
5397 {":ascent", IMAGE_ASCENT_VALUE, 0}, 5397 {":ascent", IMAGE_ASCENT_VALUE, 0},
5398 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 5398 {":margin", IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR, 0},
5399 {":relief", IMAGE_INTEGER_VALUE, 0}, 5399 {":relief", IMAGE_INTEGER_VALUE, 0},
5400 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 5400 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
5401 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 5401 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
@@ -6015,7 +6015,7 @@ static const struct image_keyword jpeg_format[JPEG_LAST] =
6015 {":data", IMAGE_STRING_VALUE, 0}, 6015 {":data", IMAGE_STRING_VALUE, 0},
6016 {":file", IMAGE_STRING_VALUE, 0}, 6016 {":file", IMAGE_STRING_VALUE, 0},
6017 {":ascent", IMAGE_ASCENT_VALUE, 0}, 6017 {":ascent", IMAGE_ASCENT_VALUE, 0},
6018 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 6018 {":margin", IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR, 0},
6019 {":relief", IMAGE_INTEGER_VALUE, 0}, 6019 {":relief", IMAGE_INTEGER_VALUE, 0},
6020 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 6020 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
6021 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 6021 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
@@ -6565,7 +6565,7 @@ static const struct image_keyword tiff_format[TIFF_LAST] =
6565 {":data", IMAGE_STRING_VALUE, 0}, 6565 {":data", IMAGE_STRING_VALUE, 0},
6566 {":file", IMAGE_STRING_VALUE, 0}, 6566 {":file", IMAGE_STRING_VALUE, 0},
6567 {":ascent", IMAGE_ASCENT_VALUE, 0}, 6567 {":ascent", IMAGE_ASCENT_VALUE, 0},
6568 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 6568 {":margin", IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR, 0},
6569 {":relief", IMAGE_INTEGER_VALUE, 0}, 6569 {":relief", IMAGE_INTEGER_VALUE, 0},
6570 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 6570 {":conversions", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
6571 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 6571 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
@@ -7002,7 +7002,7 @@ static const struct image_keyword gif_format[GIF_LAST] =
7002 {":data", IMAGE_STRING_VALUE, 0}, 7002 {":data", IMAGE_STRING_VALUE, 0},
7003 {":file", IMAGE_STRING_VALUE, 0}, 7003 {":file", IMAGE_STRING_VALUE, 0},
7004 {":ascent", IMAGE_ASCENT_VALUE, 0}, 7004 {":ascent", IMAGE_ASCENT_VALUE, 0},
7005 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 7005 {":margin", IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR, 0},
7006 {":relief", IMAGE_INTEGER_VALUE, 0}, 7006 {":relief", IMAGE_INTEGER_VALUE, 0},
7007 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 7007 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
7008 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 7008 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
@@ -7487,7 +7487,7 @@ static struct image_keyword imagemagick_format[IMAGEMAGICK_LAST] =
7487 {":data", IMAGE_STRING_VALUE, 0}, 7487 {":data", IMAGE_STRING_VALUE, 0},
7488 {":file", IMAGE_STRING_VALUE, 0}, 7488 {":file", IMAGE_STRING_VALUE, 0},
7489 {":ascent", IMAGE_ASCENT_VALUE, 0}, 7489 {":ascent", IMAGE_ASCENT_VALUE, 0},
7490 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 7490 {":margin", IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR, 0},
7491 {":relief", IMAGE_INTEGER_VALUE, 0}, 7491 {":relief", IMAGE_INTEGER_VALUE, 0},
7492 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 7492 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
7493 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 7493 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
@@ -8010,7 +8010,7 @@ static const struct image_keyword svg_format[SVG_LAST] =
8010 {":data", IMAGE_STRING_VALUE, 0}, 8010 {":data", IMAGE_STRING_VALUE, 0},
8011 {":file", IMAGE_STRING_VALUE, 0}, 8011 {":file", IMAGE_STRING_VALUE, 0},
8012 {":ascent", IMAGE_ASCENT_VALUE, 0}, 8012 {":ascent", IMAGE_ASCENT_VALUE, 0},
8013 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 8013 {":margin", IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR, 0},
8014 {":relief", IMAGE_INTEGER_VALUE, 0}, 8014 {":relief", IMAGE_INTEGER_VALUE, 0},
8015 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 8015 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
8016 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 8016 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
@@ -8405,7 +8405,7 @@ static const struct image_keyword gs_format[GS_LAST] =
8405 {":loader", IMAGE_FUNCTION_VALUE, 0}, 8405 {":loader", IMAGE_FUNCTION_VALUE, 0},
8406 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE, 1}, 8406 {":bounding-box", IMAGE_DONT_CHECK_VALUE_TYPE, 1},
8407 {":ascent", IMAGE_ASCENT_VALUE, 0}, 8407 {":ascent", IMAGE_ASCENT_VALUE, 0},
8408 {":margin", IMAGE_POSITIVE_INTEGER_VALUE_OR_PAIR, 0}, 8408 {":margin", IMAGE_NON_NEGATIVE_INTEGER_VALUE_OR_PAIR, 0},
8409 {":relief", IMAGE_INTEGER_VALUE, 0}, 8409 {":relief", IMAGE_INTEGER_VALUE, 0},
8410 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 8410 {":conversion", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
8411 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0}, 8411 {":heuristic-mask", IMAGE_DONT_CHECK_VALUE_TYPE, 0},
diff --git a/src/makefile.w32-in b/src/makefile.w32-in
index 792b66b0e4f..53cb5f857ab 100644
--- a/src/makefile.w32-in
+++ b/src/makefile.w32-in
@@ -469,6 +469,7 @@ $(BLD)/alloc.$(O) : \
469 $(SRC)/syssignal.h \ 469 $(SRC)/syssignal.h \
470 $(SRC)/w32.h \ 470 $(SRC)/w32.h \
471 $(NT_INC)/unistd.h \ 471 $(NT_INC)/unistd.h \
472 $(GNU_LIB)/verify.h \
472 $(BLOCKINPUT_H) \ 473 $(BLOCKINPUT_H) \
473 $(CHARACTER_H) \ 474 $(CHARACTER_H) \
474 $(CONFIG_H) \ 475 $(CONFIG_H) \
diff --git a/src/term.c b/src/term.c
index 48d4069e20e..fb07fc4490e 100644
--- a/src/term.c
+++ b/src/term.c
@@ -3138,11 +3138,6 @@ init_tty (const char *name, const char *terminal_type, int must_succeed)
3138 encode_terminal_src_size = 0; 3138 encode_terminal_src_size = 0;
3139 encode_terminal_dst_size = 0; 3139 encode_terminal_dst_size = 0;
3140 3140
3141#ifdef HAVE_GPM
3142 terminal->mouse_position_hook = term_mouse_position;
3143 tty->mouse_highlight.mouse_face_window = Qnil;
3144#endif
3145
3146 3141
3147#ifndef DOS_NT 3142#ifndef DOS_NT
3148 set_tty_hooks (terminal); 3143 set_tty_hooks (terminal);
@@ -3402,6 +3397,11 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3402 tty->TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */ 3397 tty->TN_max_colors = 16; /* Required to be non-zero for tty-display-color-p */
3403#endif /* DOS_NT */ 3398#endif /* DOS_NT */
3404 3399
3400#ifdef HAVE_GPM
3401 terminal->mouse_position_hook = term_mouse_position;
3402 tty->mouse_highlight.mouse_face_window = Qnil;
3403#endif
3404
3405 terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD)); 3405 terminal->kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
3406 init_kboard (terminal->kboard); 3406 init_kboard (terminal->kboard);
3407 KVAR (terminal->kboard, Vwindow_system) = Qnil; 3407 KVAR (terminal->kboard, Vwindow_system) = Qnil;
diff --git a/src/xdisp.c b/src/xdisp.c
index b60e3b466a8..2afc8fc9af1 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -8360,7 +8360,14 @@ move_it_to (struct it *it, EMACS_INT to_charpos, int to_x, int to_y, int to_vpos
8360 else if (BUFFERP (it->object) 8360 else if (BUFFERP (it->object)
8361 && (it->method == GET_FROM_BUFFER 8361 && (it->method == GET_FROM_BUFFER
8362 || it->method == GET_FROM_STRETCH) 8362 || it->method == GET_FROM_STRETCH)
8363 && IT_CHARPOS (*it) >= to_charpos) 8363 && IT_CHARPOS (*it) >= to_charpos
8364 /* Under bidi iteration, a call to set_iterator_to_next
8365 can scan far beyond to_charpos if the initial
8366 portion of the next line needs to be reordered. In
8367 that case, give move_it_in_display_line_to another
8368 chance below. */
8369 && !(it->bidi_p
8370 && it->bidi_it.scan_dir == -1))
8364 skip = MOVE_POS_MATCH_OR_ZV; 8371 skip = MOVE_POS_MATCH_OR_ZV;
8365 else 8372 else
8366 skip = move_it_in_display_line_to (it, to_charpos, -1, MOVE_TO_POS); 8373 skip = move_it_in_display_line_to (it, to_charpos, -1, MOVE_TO_POS);
@@ -8495,7 +8502,8 @@ move_it_vertically_backward (struct it *it, int dy)
8495 reseat_1 (it, it->current.pos, 1); 8502 reseat_1 (it, it->current.pos, 1);
8496 8503
8497 /* We are now surely at a line start. */ 8504 /* We are now surely at a line start. */
8498 it->current_x = it->hpos = 0; 8505 it->current_x = it->hpos = 0; /* FIXME: this is incorrect when bidi
8506 reordering is in effect. */
8499 it->continuation_lines_width = 0; 8507 it->continuation_lines_width = 0;
8500 8508
8501 /* Move forward and see what y-distance we moved. First move to the 8509 /* Move forward and see what y-distance we moved. First move to the
@@ -8529,10 +8537,25 @@ move_it_vertically_backward (struct it *it, int dy)
8529 if (dy == 0) 8537 if (dy == 0)
8530 { 8538 {
8531 /* DY == 0 means move to the start of the screen line. The 8539 /* DY == 0 means move to the start of the screen line. The
8532 value of nlines is > 0 if continuation lines were involved. */ 8540 value of nlines is > 0 if continuation lines were involved,
8541 or if the original IT position was at start of a line. */
8533 RESTORE_IT (it, it, it2data); 8542 RESTORE_IT (it, it, it2data);
8534 if (nlines > 0) 8543 if (nlines > 0)
8535 move_it_by_lines (it, nlines); 8544 move_it_by_lines (it, nlines);
8545 /* The above code moves us to some position NLINES down,
8546 usually to its first glyph (leftmost in an L2R line), but
8547 that's not necessarily the start of the line, under bidi
8548 reordering. We want to get to the character position
8549 that is immediately after the newline of the previous
8550 line. */
8551 if (it->bidi_p && IT_CHARPOS (*it) > BEGV
8552 && FETCH_BYTE (IT_BYTEPOS (*it) - 1) != '\n')
8553 {
8554 EMACS_INT nl_pos =
8555 find_next_newline_no_quit (IT_CHARPOS (*it) - 1, -1);
8556
8557 move_it_to (it, nl_pos, -1, -1, -1, MOVE_TO_POS);
8558 }
8536 bidi_unshelve_cache (it3data, 1); 8559 bidi_unshelve_cache (it3data, 1);
8537 } 8560 }
8538 else 8561 else