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,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;
}

View file

@ -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. */

View file

@ -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; \