diff options
| author | Paul Eggert | 2020-01-22 23:43:29 -0800 |
|---|---|---|
| committer | Paul Eggert | 2020-01-22 23:44:34 -0800 |
| commit | 6f580542c1796d3e7ba4d1dd40b2fe73fe00e5db (patch) | |
| tree | ed853d4d27a2f231d7fe13a4affb723d0ce28eeb | |
| parent | 5715eb94e90b33ace59dd4c4ccb6e2122bc6db72 (diff) | |
| download | emacs-6f580542c1796d3e7ba4d1dd40b2fe73fe00e5db.tar.gz emacs-6f580542c1796d3e7ba4d1dd40b2fe73fe00e5db.zip | |
Fix crash when sending Gnus message (Bug#39207)
* src/alloc.c (resize_string_data): The string must be multibyte.
When not bothering to reallocate, do bother to change the byte count.
* test/src/alloc-tests.el (aset-nbytes-change) New test.
| -rw-r--r-- | src/alloc.c | 4 | ||||
| -rw-r--r-- | test/src/alloc-tests.el | 7 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/alloc.c b/src/alloc.c index 99d5ca149d5..a35b48cfb22 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -1889,7 +1889,7 @@ allocate_string_data (struct Lisp_String *s, | |||
| 1889 | tally_consing (needed); | 1889 | tally_consing (needed); |
| 1890 | } | 1890 | } |
| 1891 | 1891 | ||
| 1892 | /* Reallocate the data for STRING when a single character is replaced. | 1892 | /* Reallocate multibyte STRING data when a single character is replaced. |
| 1893 | The character is at byte offset CIDX_BYTE in the string. | 1893 | The character is at byte offset CIDX_BYTE in the string. |
| 1894 | The character being replaced is CLEN bytes long, | 1894 | The character being replaced is CLEN bytes long, |
| 1895 | and the character that will replace it is NEW_CLEN bytes long. | 1895 | and the character that will replace it is NEW_CLEN bytes long. |
| @@ -1900,6 +1900,7 @@ unsigned char * | |||
| 1900 | resize_string_data (Lisp_Object string, ptrdiff_t cidx_byte, | 1900 | resize_string_data (Lisp_Object string, ptrdiff_t cidx_byte, |
| 1901 | int clen, int new_clen) | 1901 | int clen, int new_clen) |
| 1902 | { | 1902 | { |
| 1903 | eassume (STRING_MULTIBYTE (string)); | ||
| 1903 | sdata *old_sdata = SDATA_OF_STRING (XSTRING (string)); | 1904 | sdata *old_sdata = SDATA_OF_STRING (XSTRING (string)); |
| 1904 | ptrdiff_t nchars = SCHARS (string); | 1905 | ptrdiff_t nchars = SCHARS (string); |
| 1905 | ptrdiff_t nbytes = SBYTES (string); | 1906 | ptrdiff_t nbytes = SBYTES (string); |
| @@ -1911,6 +1912,7 @@ resize_string_data (Lisp_Object string, ptrdiff_t cidx_byte, | |||
| 1911 | { | 1912 | { |
| 1912 | /* No need to reallocate, as the size change falls within the | 1913 | /* No need to reallocate, as the size change falls within the |
| 1913 | alignment slop. */ | 1914 | alignment slop. */ |
| 1915 | XSTRING (string)->u.s.size_byte = new_nbytes; | ||
| 1914 | new_charaddr = data + cidx_byte; | 1916 | new_charaddr = data + cidx_byte; |
| 1915 | memmove (new_charaddr + new_clen, new_charaddr + clen, | 1917 | memmove (new_charaddr + new_clen, new_charaddr + clen, |
| 1916 | nbytes - (cidx_byte + (clen - 1))); | 1918 | nbytes - (cidx_byte + (clen - 1))); |
diff --git a/test/src/alloc-tests.el b/test/src/alloc-tests.el index 4eb776a0555..aa1ab1648f8 100644 --- a/test/src/alloc-tests.el +++ b/test/src/alloc-tests.el | |||
| @@ -51,3 +51,10 @@ | |||
| 51 | (should-not (eq x y)) | 51 | (should-not (eq x y)) |
| 52 | (dotimes (i 4) | 52 | (dotimes (i 4) |
| 53 | (should (eql (aref x i) (aref y i)))))) | 53 | (should (eql (aref x i) (aref y i)))))) |
| 54 | |||
| 55 | ;; Bug#39207 | ||
| 56 | (ert-deftest aset-nbytes-change () | ||
| 57 | (let ((s (make-string 1 ?a))) | ||
| 58 | (dolist (c (list 10003 ?b 128 ?c ?d (max-char) ?e)) | ||
| 59 | (aset s 0 c) | ||
| 60 | (should (equal s (make-string 1 c)))))) | ||