aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/data.c b/src/data.c
index 5a1a648dcb7..1259c5891a1 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2052,11 +2052,6 @@ or a byte-code object. IDX starts at 0. */)
2052 } 2052 }
2053} 2053}
2054 2054
2055/* Don't use alloca for relocating string data larger than this, lest
2056 we overflow their stack. The value is the same as what used in
2057 fns.c for base64 handling. */
2058#define MAX_ALLOCA 16*1024
2059
2060DEFUN ("aset", Faset, Saset, 3, 3, 0, 2055DEFUN ("aset", Faset, Saset, 3, 3, 0,
2061 doc: /* Store into the element of ARRAY at index IDX the value NEWELT. 2056 doc: /* Store into the element of ARRAY at index IDX the value NEWELT.
2062Return NEWELT. ARRAY may be a vector, a string, a char-table or a 2057Return NEWELT. ARRAY may be a vector, a string, a char-table or a
@@ -2156,10 +2151,9 @@ bool-vector. IDX starts at 0. */)
2156 /* We must relocate the string data. */ 2151 /* We must relocate the string data. */
2157 int nchars = SCHARS (array); 2152 int nchars = SCHARS (array);
2158 unsigned char *str; 2153 unsigned char *str;
2154 USE_SAFE_ALLOCA;
2159 2155
2160 str = (nbytes <= MAX_ALLOCA 2156 SAFE_ALLOCA (str, unsigned char *, nbytes);
2161 ? (unsigned char *) alloca (nbytes)
2162 : (unsigned char *) xmalloc (nbytes));
2163 bcopy (SDATA (array), str, nbytes); 2157 bcopy (SDATA (array), str, nbytes);
2164 allocate_string_data (XSTRING (array), nchars, 2158 allocate_string_data (XSTRING (array), nchars,
2165 nbytes + new_bytes - prev_bytes); 2159 nbytes + new_bytes - prev_bytes);
@@ -2167,8 +2161,7 @@ bool-vector. IDX starts at 0. */)
2167 p1 = SDATA (array) + idxval_byte; 2161 p1 = SDATA (array) + idxval_byte;
2168 bcopy (str + idxval_byte + prev_bytes, p1 + new_bytes, 2162 bcopy (str + idxval_byte + prev_bytes, p1 + new_bytes,
2169 nbytes - (idxval_byte + prev_bytes)); 2163 nbytes - (idxval_byte + prev_bytes));
2170 if (nbytes > MAX_ALLOCA) 2164 SAFE_FREE (nbytes);
2171 xfree (str);
2172 clear_string_char_byte_cache (); 2165 clear_string_char_byte_cache ();
2173 } 2166 }
2174 while (new_bytes--) 2167 while (new_bytes--)
@@ -2190,14 +2183,13 @@ bool-vector. IDX starts at 0. */)
2190 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1; 2183 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2191 unsigned char *origstr = SDATA (array), *str; 2184 unsigned char *origstr = SDATA (array), *str;
2192 int nchars, nbytes; 2185 int nchars, nbytes;
2186 USE_SAFE_ALLOCA;
2193 2187
2194 nchars = SCHARS (array); 2188 nchars = SCHARS (array);
2195 nbytes = idxval_byte = count_size_as_multibyte (origstr, idxval); 2189 nbytes = idxval_byte = count_size_as_multibyte (origstr, idxval);
2196 nbytes += count_size_as_multibyte (origstr + idxval, 2190 nbytes += count_size_as_multibyte (origstr + idxval,
2197 nchars - idxval); 2191 nchars - idxval);
2198 str = (nbytes <= MAX_ALLOCA 2192 SAFE_ALLOCA (str, unsigned char *, nbytes);
2199 ? (unsigned char *) alloca (nbytes)
2200 : (unsigned char *) xmalloc (nbytes));
2201 copy_text (SDATA (array), str, nchars, 0, 1); 2193 copy_text (SDATA (array), str, nchars, 0, 1);
2202 PARSE_MULTIBYTE_SEQ (str + idxval_byte, nbytes - idxval_byte, 2194 PARSE_MULTIBYTE_SEQ (str + idxval_byte, nbytes - idxval_byte,
2203 prev_bytes); 2195 prev_bytes);
@@ -2210,8 +2202,7 @@ bool-vector. IDX starts at 0. */)
2210 *p1++ = *p0++; 2202 *p1++ = *p0++;
2211 bcopy (str + idxval_byte + prev_bytes, p1, 2203 bcopy (str + idxval_byte + prev_bytes, p1,
2212 nbytes - (idxval_byte + prev_bytes)); 2204 nbytes - (idxval_byte + prev_bytes));
2213 if (nbytes > MAX_ALLOCA) 2205 SAFE_FREE (nbytes);
2214 xfree (str);
2215 clear_string_char_byte_cache (); 2206 clear_string_char_byte_cache ();
2216 } 2207 }
2217 } 2208 }