diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2013-06-18 22:45:35 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2013-06-18 22:45:35 -0700 |
commit | 178ba3e6f51c48ab196e44f82fc7abb3c7cd3d46 (patch) | |
tree | 7ca96e0d078f19be8b01a1b1a866b835b90abafd | |
parent | 102626e2259a927c563187d8ce3393d54a1a6b35 (diff) | |
download | emacs-178ba3e6f51c48ab196e44f82fc7abb3c7cd3d46.tar.gz |
* syntax.c (skip_chars): Don't use uninitialized storage
when searching a multibyte buffer for characters that are not in a
unibyte string that contains non-ASCII characters.
-rw-r--r-- | src/ChangeLog | 6 | ||||
-rw-r--r-- | src/syntax.c | 45 |
2 files changed, 27 insertions, 24 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 2454935169f..4d39cc70c23 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2013-06-19 Paul Eggert <eggert@cs.ucla.edu> + + * syntax.c (skip_chars): Don't use uninitialized storage + when searching a multibyte buffer for characters that are not in a + unibyte string that contains non-ASCII characters. + 2013-06-18 Jan Djärv <jan.h.d@swipnet.se> * process.c: Include xgselect.h if HAVE_GLIB. Include glib.h diff --git a/src/syntax.c b/src/syntax.c index 390d732944d..1b76f56dea6 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -1577,34 +1577,31 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl the corresponding multibyte chars. */ if (multibyte && string_has_eight_bit) { - unsigned char fastmap2[0400]; - int range_start_byte, range_start_char; - - memcpy (fastmap + 0200, fastmap2 + 0200, 0200); + char *p1; + char himap[0200 + 1]; + memcpy (himap, fastmap + 0200, 0200); + himap[0200] = 0; memset (fastmap + 0200, 0, 0200); - /* We are sure that this loop stops. */ - for (i = 0200; ! fastmap2[i]; i++); - c = BYTE8_TO_CHAR (i); - fastmap[CHAR_LEADING_CODE (c)] = 1; - range_start_byte = i; - range_start_char = c; char_ranges = alloca (sizeof *char_ranges * 128 * 2); - for (i = 129; i < 0400; i++) + i = 0; + + while ((p1 = memchr (himap + i, 1, 0200 - i))) { - c = BYTE8_TO_CHAR (i); - fastmap[CHAR_LEADING_CODE (c)] = 1; - if (i - range_start_byte != c - range_start_char) - { - char_ranges[n_char_ranges++] = range_start_char; - char_ranges[n_char_ranges++] = ((i - 1 - range_start_byte) - + range_start_char); - range_start_byte = i; - range_start_char = c; - } + /* Deduce the next range C..C2 from the next clump of 1s + in HIMAP starting with &HIMAP[I]. HIMAP is the high + order half of the old FASTMAP. */ + int c2, leading_code; + i = p1 - himap; + c = BYTE8_TO_CHAR (i + 0200); + i += strlen (p1); + c2 = BYTE8_TO_CHAR (i + 0200 - 1); + + char_ranges[n_char_ranges++] = c; + char_ranges[n_char_ranges++] = c2; + leading_code = CHAR_LEADING_CODE (c); + memset (fastmap + leading_code, 1, + CHAR_LEADING_CODE (c2) - leading_code + 1); } - char_ranges[n_char_ranges++] = range_start_char; - char_ranges[n_char_ranges++] = ((i - 1 - range_start_byte) - + range_start_char); } } else /* STRING is multibyte */ |