aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
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/alloc.c
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/alloc.c')
-rw-r--r--src/alloc.c13
1 files changed, 9 insertions, 4 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