aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2018-12-12 09:54:42 -0800
committerPaul Eggert2018-12-12 09:55:38 -0800
commit8a247f6059066636fbb60e79f6a9580ee9a81495 (patch)
treed149637a6ca2ddaca1d596dbfddefb6402c9ed3c /src
parent23e9e8abaab6f0c90412fc5fae08e5995a26d84c (diff)
downloademacs-8a247f6059066636fbb60e79f6a9580ee9a81495.tar.gz
emacs-8a247f6059066636fbb60e79f6a9580ee9a81495.zip
Simplify validate_interval_range and callers
* src/textprop.c (validate_interval_range): Remove useless code. Fix comment to match current behavior. (set_text_properties, copy_text_properties): Simplify, as validate_interval_range has not incremented START or END for quite some time. (copy_text_properties): Assume C99. Fix an unlikely integer overflow bug if WIDE_EMACS_INT.
Diffstat (limited to 'src')
-rw-r--r--src/textprop.c60
1 files changed, 16 insertions, 44 deletions
diff --git a/src/textprop.c b/src/textprop.c
index add14eb4a78..8a06f0ffad1 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -111,9 +111,6 @@ CHECK_STRING_OR_BUFFER (Lisp_Object x)
111 to by BEGIN and END may be integers or markers; if the latter, they 111 to by BEGIN and END may be integers or markers; if the latter, they
112 are coerced to integers. 112 are coerced to integers.
113 113
114 When OBJECT is a string, we increment *BEGIN and *END
115 to make them origin-one.
116
117 Note that buffer points don't correspond to interval indices. 114 Note that buffer points don't correspond to interval indices.
118 For example, point-max is 1 greater than the index of the last 115 For example, point-max is 1 greater than the index of the last
119 character. This difference is handled in the caller, which uses 116 character. This difference is handled in the caller, which uses
@@ -175,9 +172,6 @@ validate_interval_range (Lisp_Object object, Lisp_Object *begin,
175 if (! (0 <= XFIXNUM (*begin) && XFIXNUM (*begin) <= XFIXNUM (*end) 172 if (! (0 <= XFIXNUM (*begin) && XFIXNUM (*begin) <= XFIXNUM (*end)
176 && XFIXNUM (*end) <= len)) 173 && XFIXNUM (*end) <= len))
177 args_out_of_range (*begin, *end); 174 args_out_of_range (*begin, *end);
178 XSETFASTINT (*begin, XFIXNAT (*begin));
179 if (begin != end)
180 XSETFASTINT (*end, XFIXNAT (*end));
181 i = string_intervals (object); 175 i = string_intervals (object);
182 176
183 if (len == 0) 177 if (len == 0)
@@ -1348,13 +1342,9 @@ Lisp_Object
1348set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties, 1342set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
1349 Lisp_Object object, Lisp_Object coherent_change_p) 1343 Lisp_Object object, Lisp_Object coherent_change_p)
1350{ 1344{
1351 register INTERVAL i; 1345 INTERVAL i;
1352 Lisp_Object ostart, oend;
1353 bool first_time = true; 1346 bool first_time = true;
1354 1347
1355 ostart = start;
1356 oend = end;
1357
1358 properties = validate_plist (properties); 1348 properties = validate_plist (properties);
1359 1349
1360 if (NILP (object)) 1350 if (NILP (object))
@@ -1382,11 +1372,6 @@ set_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object properties,
1382 if (NILP (properties)) 1372 if (NILP (properties))
1383 return Qnil; 1373 return Qnil;
1384 1374
1385 /* Restore the original START and END values
1386 because validate_interval_range increments them for strings. */
1387 start = ostart;
1388 end = oend;
1389
1390 i = validate_interval_range (object, &start, &end, hard); 1375 i = validate_interval_range (object, &start, &end, hard);
1391 /* This can return if start == end. */ 1376 /* This can return if start == end. */
1392 if (!i) 1377 if (!i)
@@ -1887,45 +1872,30 @@ Lisp_Object
1887copy_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object src, 1872copy_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object src,
1888 Lisp_Object pos, Lisp_Object dest, Lisp_Object prop) 1873 Lisp_Object pos, Lisp_Object dest, Lisp_Object prop)
1889{ 1874{
1890 INTERVAL i; 1875 INTERVAL i = validate_interval_range (src, &start, &end, soft);
1891 Lisp_Object res;
1892 Lisp_Object stuff;
1893 Lisp_Object plist;
1894 ptrdiff_t s, e, e2, p, len;
1895 bool modified = false;
1896
1897 i = validate_interval_range (src, &start, &end, soft);
1898 if (!i) 1876 if (!i)
1899 return Qnil; 1877 return Qnil;
1900 1878
1901 CHECK_FIXNUM_COERCE_MARKER (pos); 1879 CHECK_FIXNUM_COERCE_MARKER (pos);
1902 {
1903 Lisp_Object dest_start, dest_end;
1904
1905 e = XFIXNUM (pos) + (XFIXNUM (end) - XFIXNUM (start));
1906 if (MOST_POSITIVE_FIXNUM < e)
1907 args_out_of_range (pos, end);
1908 dest_start = pos;
1909 XSETFASTINT (dest_end, e);
1910 /* Apply this to a copy of pos; it will try to increment its arguments,
1911 which we don't want. */
1912 validate_interval_range (dest, &dest_start, &dest_end, soft);
1913 }
1914 1880
1915 s = XFIXNUM (start); 1881 EMACS_INT dest_e = XFIXNUM (pos) + (XFIXNUM (end) - XFIXNUM (start));
1916 e = XFIXNUM (end); 1882 if (MOST_POSITIVE_FIXNUM < dest_e)
1917 p = XFIXNUM (pos); 1883 args_out_of_range (pos, end);
1884 Lisp_Object dest_end = make_fixnum (dest_e);
1885 validate_interval_range (dest, &pos, &dest_end, soft);
1918 1886
1919 stuff = Qnil; 1887 ptrdiff_t s = XFIXNUM (start), e = XFIXNUM (end), p = XFIXNUM (pos);
1888
1889 Lisp_Object stuff = Qnil;
1920 1890
1921 while (s < e) 1891 while (s < e)
1922 { 1892 {
1923 e2 = i->position + LENGTH (i); 1893 ptrdiff_t e2 = i->position + LENGTH (i);
1924 if (e2 > e) 1894 if (e2 > e)
1925 e2 = e; 1895 e2 = e;
1926 len = e2 - s; 1896 ptrdiff_t len = e2 - s;
1927 1897
1928 plist = i->plist; 1898 Lisp_Object plist = i->plist;
1929 if (! NILP (prop)) 1899 if (! NILP (prop))
1930 while (! NILP (plist)) 1900 while (! NILP (plist))
1931 { 1901 {
@@ -1950,9 +1920,11 @@ copy_text_properties (Lisp_Object start, Lisp_Object end, Lisp_Object src,
1950 s = i->position; 1920 s = i->position;
1951 } 1921 }
1952 1922
1923 bool modified = false;
1924
1953 while (! NILP (stuff)) 1925 while (! NILP (stuff))
1954 { 1926 {
1955 res = Fcar (stuff); 1927 Lisp_Object res = Fcar (stuff);
1956 res = Fadd_text_properties (Fcar (res), Fcar (Fcdr (res)), 1928 res = Fadd_text_properties (Fcar (res), Fcar (Fcdr (res)),
1957 Fcar (Fcdr (Fcdr (res))), dest); 1929 Fcar (Fcdr (Fcdr (res))), dest);
1958 if (! NILP (res)) 1930 if (! NILP (res))