aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYAMAMOTO Mitsuharu2015-12-31 10:59:40 +0900
committerYAMAMOTO Mitsuharu2015-12-31 10:59:40 +0900
commit47580e0d72f53c2fff23cb8edf1487da76e87744 (patch)
treee81c698d019e12a680aed3c0867a7c04d49cc4af /src
parent0588be7ca658faf79bbff7ffcb7eb9f0e3fb8190 (diff)
downloademacs-47580e0d72f53c2fff23cb8edf1487da76e87744.tar.gz
emacs-47580e0d72f53c2fff23cb8edf1487da76e87744.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c13
-rw-r--r--src/character.h2
-rw-r--r--src/lisp.h4
3 files changed, 11 insertions, 8 deletions
diff --git a/src/alloc.c b/src/alloc.c
index fe55cde49c9..49f5b7f18bc 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -2119,8 +2119,11 @@ INIT must be an integer that represents a character. */)
2119 { 2119 {
2120 nbytes = XINT (length); 2120 nbytes = XINT (length);
2121 val = make_uninit_string (nbytes); 2121 val = make_uninit_string (nbytes);
2122 memset (SDATA (val), c, nbytes); 2122 if (nbytes)
2123 SDATA (val)[nbytes] = 0; 2123 {
2124 memset (SDATA (val), c, nbytes);
2125 SDATA (val)[nbytes] = 0;
2126 }
2124 } 2127 }
2125 else 2128 else
2126 { 2129 {
@@ -2145,7 +2148,8 @@ INIT must be an integer that represents a character. */)
2145 memcpy (p, beg, len); 2148 memcpy (p, beg, len);
2146 } 2149 }
2147 } 2150 }
2148 *p = 0; 2151 if (nbytes)
2152 *p = 0;
2149 } 2153 }
2150 2154
2151 return val; 2155 return val;
@@ -3188,7 +3192,8 @@ allocate_vector (EMACS_INT len)
3188 if (min ((nbytes_max - header_size) / word_size, MOST_POSITIVE_FIXNUM) < len) 3192 if (min ((nbytes_max - header_size) / word_size, MOST_POSITIVE_FIXNUM) < len)
3189 memory_full (SIZE_MAX); 3193 memory_full (SIZE_MAX);
3190 v = allocate_vectorlike (len); 3194 v = allocate_vectorlike (len);
3191 v->header.size = len; 3195 if (len)
3196 v->header.size = len;
3192 return v; 3197 return v;
3193} 3198}
3194 3199
diff --git a/src/character.h b/src/character.h
index 871c1c3de95..440e78147d1 100644
--- a/src/character.h
+++ b/src/character.h
@@ -135,14 +135,12 @@ enum
135 do { \ 135 do { \
136 Lisp_Object tmp = XCAR (x); \ 136 Lisp_Object tmp = XCAR (x); \
137 CHECK_CHARACTER (tmp); \ 137 CHECK_CHARACTER (tmp); \
138 XSETCAR ((x), tmp); \
139 } while (false) 138 } while (false)
140 139
141#define CHECK_CHARACTER_CDR(x) \ 140#define CHECK_CHARACTER_CDR(x) \
142 do { \ 141 do { \
143 Lisp_Object tmp = XCDR (x); \ 142 Lisp_Object tmp = XCDR (x); \
144 CHECK_CHARACTER (tmp); \ 143 CHECK_CHARACTER (tmp); \
145 XSETCDR ((x), tmp); \
146 } while (false) 144 } while (false)
147 145
148/* Nonzero iff C is a character of code less than 0x100. */ 146/* Nonzero iff C is a character of code less than 0x100. */
diff --git a/src/lisp.h b/src/lisp.h
index 995760a5019..477521bbf4e 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1325,7 +1325,7 @@ STRING_MULTIBYTE (Lisp_Object str)
1325/* Mark STR as a unibyte string. */ 1325/* Mark STR as a unibyte string. */
1326#define STRING_SET_UNIBYTE(STR) \ 1326#define STRING_SET_UNIBYTE(STR) \
1327 do { \ 1327 do { \
1328 if (EQ (STR, empty_multibyte_string)) \ 1328 if (XSTRING (STR)->size == 0) \
1329 (STR) = empty_unibyte_string; \ 1329 (STR) = empty_unibyte_string; \
1330 else \ 1330 else \
1331 XSTRING (STR)->size_byte = -1; \ 1331 XSTRING (STR)->size_byte = -1; \
@@ -1335,7 +1335,7 @@ STRING_MULTIBYTE (Lisp_Object str)
1335 ASCII characters in advance. */ 1335 ASCII characters in advance. */
1336#define STRING_SET_MULTIBYTE(STR) \ 1336#define STRING_SET_MULTIBYTE(STR) \
1337 do { \ 1337 do { \
1338 if (EQ (STR, empty_unibyte_string)) \ 1338 if (XSTRING (STR)->size == 0) \
1339 (STR) = empty_multibyte_string; \ 1339 (STR) = empty_multibyte_string; \
1340 else \ 1340 else \
1341 XSTRING (STR)->size_byte = XSTRING (STR)->size; \ 1341 XSTRING (STR)->size_byte = XSTRING (STR)->size; \