aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2014-02-13 16:16:42 +0400
committerDmitry Antipov2014-02-13 16:16:42 +0400
commit28c16c40704c05721077617faad01cf6526fbc0c (patch)
treea2d8db05106f70799eff3eeafc499aae96336ac6 /src
parentace9793861c5ccc602143d9bbe8f6e1a4e429370 (diff)
downloademacs-28c16c40704c05721077617faad01cf6526fbc0c.tar.gz
emacs-28c16c40704c05721077617faad01cf6526fbc0c.zip
* composite.c (fill_gstring_header): Pass positions as C integers
and move parameters checking to... * composite.c (Fcomposition_get_gstring): ...this function. Handle case when buffer positions are in reversed order and avoid crash (Bug#16739). Adjust docstring. * buffer.c (validate_region): Mention current buffer in error message.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog9
-rw-r--r--src/buffer.c2
-rw-r--r--src/composite.c64
3 files changed, 41 insertions, 34 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index a8bc522939c..5ea85516c71 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
12014-02-13 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * composite.c (fill_gstring_header): Pass positions as C integers
4 and move parameters checking to...
5 * composite.c (Fcomposition_get_gstring): ...this function. Handle
6 case when buffer positions are in reversed order and avoid crash
7 (Bug#16739). Adjust docstring.
8 * buffer.c (validate_region): Mention current buffer in error message.
9
12014-02-12 Marcus Karlsson <mk@acc.umu.se> (tiny change) 102014-02-12 Marcus Karlsson <mk@acc.umu.se> (tiny change)
2 11
3 * image.c (pbm_load): Set to NO_PIXMAP on error (Bug#16683). 12 * image.c (pbm_load): Set to NO_PIXMAP on error (Bug#16683).
diff --git a/src/buffer.c b/src/buffer.c
index 42c4c1306a9..90c15420d1d 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -2261,7 +2261,7 @@ validate_region (register Lisp_Object *b, register Lisp_Object *e)
2261 } 2261 }
2262 2262
2263 if (! (BEGV <= XINT (*b) && XINT (*e) <= ZV)) 2263 if (! (BEGV <= XINT (*b) && XINT (*e) <= ZV))
2264 args_out_of_range (*b, *e); 2264 args_out_of_range_3 (Fcurrent_buffer (), *b, *e);
2265} 2265}
2266 2266
2267/* Advance BYTE_POS up to a character boundary 2267/* Advance BYTE_POS up to a character boundary
diff --git a/src/composite.c b/src/composite.c
index 04cfe5efee0..fa882141908 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -780,35 +780,11 @@ static Lisp_Object gstring_work;
780static Lisp_Object gstring_work_headers; 780static Lisp_Object gstring_work_headers;
781 781
782static Lisp_Object 782static Lisp_Object
783fill_gstring_header (Lisp_Object header, Lisp_Object start, Lisp_Object end, 783fill_gstring_header (Lisp_Object header, ptrdiff_t from, ptrdiff_t from_byte,
784 Lisp_Object font_object, Lisp_Object string) 784 ptrdiff_t to, Lisp_Object font_object, Lisp_Object string)
785{ 785{
786 ptrdiff_t from, to, from_byte; 786 ptrdiff_t len = to - from, i;
787 ptrdiff_t len, i;
788 787
789 if (NILP (string))
790 {
791 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
792 error ("Attempt to shape unibyte text");
793 validate_region (&start, &end);
794 from = XFASTINT (start);
795 to = XFASTINT (end);
796 from_byte = CHAR_TO_BYTE (from);
797 }
798 else
799 {
800 CHECK_STRING (string);
801 if (! STRING_MULTIBYTE (string))
802 error ("Attempt to shape unibyte text");
803 /* The caller checks that START and END are nonnegative integers. */
804 if (! (XINT (start) <= XINT (end) && XINT (end) <= SCHARS (string)))
805 args_out_of_range_3 (string, start, end);
806 from = XINT (start);
807 to = XINT (end);
808 from_byte = string_char_to_byte (string, from);
809 }
810
811 len = to - from;
812 if (len == 0) 788 if (len == 0)
813 error ("Attempt to shape zero-length text"); 789 error ("Attempt to shape zero-length text");
814 if (VECTORP (header)) 790 if (VECTORP (header))
@@ -1708,6 +1684,8 @@ frame, or nil for the selected frame's terminal device.
1708 1684
1709If the optional 4th argument STRING is not nil, it is a string 1685If the optional 4th argument STRING is not nil, it is a string
1710containing the target characters between indices FROM and TO. 1686containing the target characters between indices FROM and TO.
1687Otherwise FROM and TO are character positions in current buffer;
1688they can be in either order, and can be integers or markers.
1711 1689
1712A glyph-string is a vector containing information about how to display 1690A glyph-string is a vector containing information about how to display
1713a specific character sequence. The format is: 1691a specific character sequence. The format is:
@@ -1739,10 +1717,8 @@ should be ignored. */)
1739 (Lisp_Object from, Lisp_Object to, Lisp_Object font_object, Lisp_Object string) 1717 (Lisp_Object from, Lisp_Object to, Lisp_Object font_object, Lisp_Object string)
1740{ 1718{
1741 Lisp_Object gstring, header; 1719 Lisp_Object gstring, header;
1742 ptrdiff_t frompos, topos; 1720 ptrdiff_t frompos, frombyte, topos;
1743 1721
1744 CHECK_NATNUM (from);
1745 CHECK_NATNUM (to);
1746 if (! FONT_OBJECT_P (font_object)) 1722 if (! FONT_OBJECT_P (font_object))
1747 { 1723 {
1748 struct coding_system *coding; 1724 struct coding_system *coding;
@@ -1754,13 +1730,35 @@ should be ignored. */)
1754 font_object = CODING_ID_NAME (coding->id); 1730 font_object = CODING_ID_NAME (coding->id);
1755 } 1731 }
1756 1732
1757 header = fill_gstring_header (Qnil, from, to, font_object, string); 1733 if (NILP (string))
1734 {
1735 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
1736 error ("Attempt to shape unibyte text");
1737 validate_region (&from, &to);
1738 frompos = XFASTINT (from);
1739 topos = XFASTINT (to);
1740 frombyte = CHAR_TO_BYTE (frompos);
1741 }
1742 else
1743 {
1744 CHECK_NATNUM (from);
1745 CHECK_NATNUM (to);
1746 CHECK_STRING (string);
1747 if (! STRING_MULTIBYTE (string))
1748 error ("Attempt to shape unibyte text");
1749 if (! (XINT (from) <= XINT (to) && XINT (to) <= SCHARS (string)))
1750 args_out_of_range_3 (string, from, to);
1751 frompos = XFASTINT (from);
1752 topos = XFASTINT (to);
1753 frombyte = string_char_to_byte (string, frompos);
1754 }
1755
1756 header = fill_gstring_header (Qnil, frompos, frombyte,
1757 topos, font_object, string);
1758 gstring = gstring_lookup_cache (header); 1758 gstring = gstring_lookup_cache (header);
1759 if (! NILP (gstring)) 1759 if (! NILP (gstring))
1760 return gstring; 1760 return gstring;
1761 1761
1762 frompos = XINT (from);
1763 topos = XINT (to);
1764 if (LGSTRING_GLYPH_LEN (gstring_work) < topos - frompos) 1762 if (LGSTRING_GLYPH_LEN (gstring_work) < topos - frompos)
1765 gstring_work = Fmake_vector (make_number (topos - frompos + 2), Qnil); 1763 gstring_work = Fmake_vector (make_number (topos - frompos + 2), Qnil);
1766 LGSTRING_SET_HEADER (gstring_work, header); 1764 LGSTRING_SET_HEADER (gstring_work, header);