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.
This commit is contained in:
YAMAMOTO Mitsuharu 2015-12-31 10:59:40 +09:00
parent 0588be7ca6
commit 47580e0d72
3 changed files with 11 additions and 8 deletions

View file

@ -2119,9 +2119,12 @@ INIT must be an integer that represents a character. */)
{ {
nbytes = XINT (length); nbytes = XINT (length);
val = make_uninit_string (nbytes); val = make_uninit_string (nbytes);
if (nbytes)
{
memset (SDATA (val), c, nbytes); memset (SDATA (val), c, nbytes);
SDATA (val)[nbytes] = 0; SDATA (val)[nbytes] = 0;
} }
}
else else
{ {
unsigned char str[MAX_MULTIBYTE_LENGTH]; unsigned char str[MAX_MULTIBYTE_LENGTH];
@ -2145,6 +2148,7 @@ INIT must be an integer that represents a character. */)
memcpy (p, beg, len); memcpy (p, beg, len);
} }
} }
if (nbytes)
*p = 0; *p = 0;
} }
@ -3188,6 +3192,7 @@ allocate_vector (EMACS_INT len)
if (min ((nbytes_max - header_size) / word_size, MOST_POSITIVE_FIXNUM) < len) if (min ((nbytes_max - header_size) / word_size, MOST_POSITIVE_FIXNUM) < len)
memory_full (SIZE_MAX); memory_full (SIZE_MAX);
v = allocate_vectorlike (len); v = allocate_vectorlike (len);
if (len)
v->header.size = len; v->header.size = len;
return v; return v;
} }

View file

@ -135,14 +135,12 @@ enum
do { \ do { \
Lisp_Object tmp = XCAR (x); \ Lisp_Object tmp = XCAR (x); \
CHECK_CHARACTER (tmp); \ CHECK_CHARACTER (tmp); \
XSETCAR ((x), tmp); \
} while (false) } while (false)
#define CHECK_CHARACTER_CDR(x) \ #define CHECK_CHARACTER_CDR(x) \
do { \ do { \
Lisp_Object tmp = XCDR (x); \ Lisp_Object tmp = XCDR (x); \
CHECK_CHARACTER (tmp); \ CHECK_CHARACTER (tmp); \
XSETCDR ((x), tmp); \
} while (false) } while (false)
/* Nonzero iff C is a character of code less than 0x100. */ /* Nonzero iff C is a character of code less than 0x100. */

View file

@ -1325,7 +1325,7 @@ STRING_MULTIBYTE (Lisp_Object str)
/* Mark STR as a unibyte string. */ /* Mark STR as a unibyte string. */
#define STRING_SET_UNIBYTE(STR) \ #define STRING_SET_UNIBYTE(STR) \
do { \ do { \
if (EQ (STR, empty_multibyte_string)) \ if (XSTRING (STR)->size == 0) \
(STR) = empty_unibyte_string; \ (STR) = empty_unibyte_string; \
else \ else \
XSTRING (STR)->size_byte = -1; \ XSTRING (STR)->size_byte = -1; \
@ -1335,7 +1335,7 @@ STRING_MULTIBYTE (Lisp_Object str)
ASCII characters in advance. */ ASCII characters in advance. */
#define STRING_SET_MULTIBYTE(STR) \ #define STRING_SET_MULTIBYTE(STR) \
do { \ do { \
if (EQ (STR, empty_unibyte_string)) \ if (XSTRING (STR)->size == 0) \
(STR) = empty_multibyte_string; \ (STR) = empty_multibyte_string; \
else \ else \
XSTRING (STR)->size_byte = XSTRING (STR)->size; \ XSTRING (STR)->size_byte = XSTRING (STR)->size; \