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:
parent
0588be7ca6
commit
47580e0d72
3 changed files with 11 additions and 8 deletions
13
src/alloc.c
13
src/alloc.c
|
@ -2119,8 +2119,11 @@ 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);
|
||||||
memset (SDATA (val), c, nbytes);
|
if (nbytes)
|
||||||
SDATA (val)[nbytes] = 0;
|
{
|
||||||
|
memset (SDATA (val), c, nbytes);
|
||||||
|
SDATA (val)[nbytes] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2145,7 +2148,8 @@ INIT must be an integer that represents a character. */)
|
||||||
memcpy (p, beg, len);
|
memcpy (p, beg, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*p = 0;
|
if (nbytes)
|
||||||
|
*p = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
|
@ -3188,7 +3192,8 @@ 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);
|
||||||
v->header.size = len;
|
if (len)
|
||||||
|
v->header.size = len;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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. */
|
||||||
|
|
|
@ -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; \
|
||||||
|
|
Loading…
Add table
Reference in a new issue