Skip to content

Commit 6f58054

Browse files
committed
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.
1 parent 5715eb9 commit 6f58054

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/alloc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ allocate_string_data (struct Lisp_String *s,
18891889
tally_consing (needed);
18901890
}
18911891

1892-
/* Reallocate the data for STRING when a single character is replaced.
1892+
/* Reallocate multibyte STRING data when a single character is replaced.
18931893
The character is at byte offset CIDX_BYTE in the string.
18941894
The character being replaced is CLEN bytes long,
18951895
and the character that will replace it is NEW_CLEN bytes long.
@@ -1900,6 +1900,7 @@ unsigned char *
19001900
resize_string_data (Lisp_Object string, ptrdiff_t cidx_byte,
19011901
int clen, int new_clen)
19021902
{
1903+
eassume (STRING_MULTIBYTE (string));
19031904
sdata *old_sdata = SDATA_OF_STRING (XSTRING (string));
19041905
ptrdiff_t nchars = SCHARS (string);
19051906
ptrdiff_t nbytes = SBYTES (string);
@@ -1911,6 +1912,7 @@ resize_string_data (Lisp_Object string, ptrdiff_t cidx_byte,
19111912
{
19121913
/* No need to reallocate, as the size change falls within the
19131914
alignment slop. */
1915+
XSTRING (string)->u.s.size_byte = new_nbytes;
19141916
new_charaddr = data + cidx_byte;
19151917
memmove (new_charaddr + new_clen, new_charaddr + clen,
19161918
nbytes - (cidx_byte + (clen - 1)));

test/src/alloc-tests.el

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,10 @@
5151
(should-not (eq x y))
5252
(dotimes (i 4)
5353
(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))))))

0 commit comments

Comments
 (0)