]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix clear-string crash with text properties
authorStefan Kangas <stefankangas@gmail.com>
Wed, 15 Jan 2025 22:11:16 +0000 (23:11 +0100)
committerEshel Yaron <me@eshelyaron.com>
Fri, 17 Jan 2025 11:35:01 +0000 (12:35 +0100)
* src/fns.c (Fclear_string): Fix crash by clearing all text
properties.  (Bug#75581)
* doc/lispref/strings.texi (Modifying Strings): Document the above
behavior change.
Fix proposed by Andreas Schwab <schwab@linux-m68k.org>.

(cherry picked from commit 4f946a652278cc72a777fe56999bc4525f53e03a)

doc/lispref/strings.texi
src/fns.c

index da0c1abd3488d20e8c29715727059ae4fe77b541..93025574893a1702b5dd1d477cdfecdba4225939 100644 (file)
@@ -478,8 +478,9 @@ a raw byte.
 @code{clear-string}:
 
 @defun clear-string string
-This makes @var{string} a unibyte string and clears its contents to
-null characters.  It may also change @var{string}'s length.
+This makes @var{string} a unibyte string, clears its contents to null
+characters, and removes all text properties.  It may also change
+@var{string}'s length.
 @end defun
 
 @need 2000
index 12c7fc017cd347cf8e157f0ad920183fca3c7331..11348c12c53a1e00771a824841a919fb405d226f 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -3305,14 +3305,16 @@ ARRAY is a vector, string, char-table, or bool-vector.  */)
   return array;
 }
 
-DEFUN ("clear-string", Fclear_string, Sclear_string,
-       1, 1, 0,
+DEFUN ("clear-string", Fclear_string, Sclear_string, 1, 1, 0,
        doc: /* Clear the contents of STRING.
-This makes STRING unibyte and may change its length.  */)
+This makes STRING unibyte, clears its contents to null characters, and
+removes all text properties.  This may change its length.  */)
   (Lisp_Object string)
 {
   CHECK_STRING (string);
   ptrdiff_t len = SBYTES (string);
+  Fset_text_properties (make_fixnum (0), make_fixnum (SCHARS (string)),
+                       Qnil, string);
   if (len != 0 || STRING_MULTIBYTE (string))
     {
       CHECK_IMPURE (string, XSTRING (string));