emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-25 47580e0: Avoid writing to purespace


From: YAMAMOTO Mitsuharu
Subject: [Emacs-diffs] emacs-25 47580e0: Avoid writing to purespace
Date: Thu, 31 Dec 2015 02:00:37 +0000

branch: emacs-25
commit 47580e0d72f53c2fff23cb8edf1487da76e87744
Author: YAMAMOTO Mitsuharu <address@hidden>
Commit: YAMAMOTO Mitsuharu <address@hidden>

    Avoid writing to purespace
    
    * src/alloc.c (Fmake_string): Don't write to empty string contents.
    (allocate_vector): Don't write to empty vector size.
    * src/character.h (CHECK_CHARACTER_CAR, CHECK_CHARACTER_CDR):
    Don't call unnecessary XSETCAR or XSETCDR.
    * src/lisp.h (STRING_SET_UNIBYTE, STRING_SET_MULTIBYTE): Don't
    write to empty string size_byte.
---
 src/alloc.c     |   13 +++++++++----
 src/character.h |    2 --
 src/lisp.h      |    4 ++--
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/alloc.c b/src/alloc.c
index fe55cde..49f5b7f 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -2119,8 +2119,11 @@ INIT must be an integer that represents a character.  */)
     {
       nbytes = XINT (length);
       val = make_uninit_string (nbytes);
-      memset (SDATA (val), c, nbytes);
-      SDATA (val)[nbytes] = 0;
+      if (nbytes)
+       {
+         memset (SDATA (val), c, nbytes);
+         SDATA (val)[nbytes] = 0;
+       }
     }
   else
     {
@@ -2145,7 +2148,8 @@ INIT must be an integer that represents a character.  */)
              memcpy (p, beg, len);
            }
        }
-      *p = 0;
+      if (nbytes)
+       *p = 0;
     }
 
   return val;
@@ -3188,7 +3192,8 @@ allocate_vector (EMACS_INT len)
   if (min ((nbytes_max - header_size) / word_size, MOST_POSITIVE_FIXNUM) < len)
     memory_full (SIZE_MAX);
   v = allocate_vectorlike (len);
-  v->header.size = len;
+  if (len)
+    v->header.size = len;
   return v;
 }
 
diff --git a/src/character.h b/src/character.h
index 871c1c3..440e781 100644
--- a/src/character.h
+++ b/src/character.h
@@ -135,14 +135,12 @@ enum
   do {                                 \
     Lisp_Object tmp = XCAR (x);                \
     CHECK_CHARACTER (tmp);             \
-    XSETCAR ((x), tmp);                        \
   } while (false)
 
 #define CHECK_CHARACTER_CDR(x) \
   do {                                 \
     Lisp_Object tmp = XCDR (x);                \
     CHECK_CHARACTER (tmp);             \
-    XSETCDR ((x), tmp);                        \
   } while (false)
 
 /* Nonzero iff C is a character of code less than 0x100.  */
diff --git a/src/lisp.h b/src/lisp.h
index 995760a..477521b 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1325,7 +1325,7 @@ STRING_MULTIBYTE (Lisp_Object str)
 /* Mark STR as a unibyte string.  */
 #define STRING_SET_UNIBYTE(STR)                                \
   do {                                                 \
-    if (EQ (STR, empty_multibyte_string))              \
+    if (XSTRING (STR)->size == 0)                      \
       (STR) = empty_unibyte_string;                    \
     else                                               \
       XSTRING (STR)->size_byte = -1;                   \
@@ -1335,7 +1335,7 @@ STRING_MULTIBYTE (Lisp_Object str)
    ASCII characters in advance.  */
 #define STRING_SET_MULTIBYTE(STR)                      \
   do {                                                 \
-    if (EQ (STR, empty_unibyte_string))                        \
+    if (XSTRING (STR)->size == 0)                      \
       (STR) = empty_multibyte_string;                  \
     else                                               \
       XSTRING (STR)->size_byte = XSTRING (STR)->size;  \



reply via email to

[Prev in Thread] Current Thread [Next in Thread]