diff options
Diffstat (limited to 'src/fns.c')
| -rw-r--r-- | src/fns.c | 50 |
1 files changed, 22 insertions, 28 deletions
| @@ -23,6 +23,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 23 | #include <time.h> | 23 | #include <time.h> |
| 24 | #include <setjmp.h> | 24 | #include <setjmp.h> |
| 25 | 25 | ||
| 26 | #include <intprops.h> | ||
| 27 | |||
| 26 | #include "lisp.h" | 28 | #include "lisp.h" |
| 27 | #include "commands.h" | 29 | #include "commands.h" |
| 28 | #include "character.h" | 30 | #include "character.h" |
| @@ -567,8 +569,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args, | |||
| 567 | } | 569 | } |
| 568 | 570 | ||
| 569 | result_len += len; | 571 | result_len += len; |
| 570 | if (result_len < 0) | 572 | if (STRING_BYTES_BOUND < result_len) |
| 571 | error ("String overflow"); | 573 | string_overflow (); |
| 572 | } | 574 | } |
| 573 | 575 | ||
| 574 | if (! some_multibyte) | 576 | if (! some_multibyte) |
| @@ -2141,7 +2143,6 @@ ARRAY is a vector, string, char-table, or bool-vector. */) | |||
| 2141 | (Lisp_Object array, Lisp_Object item) | 2143 | (Lisp_Object array, Lisp_Object item) |
| 2142 | { | 2144 | { |
| 2143 | register EMACS_INT size, idx; | 2145 | register EMACS_INT size, idx; |
| 2144 | int charval; | ||
| 2145 | 2146 | ||
| 2146 | if (VECTORP (array)) | 2147 | if (VECTORP (array)) |
| 2147 | { | 2148 | { |
| @@ -2161,27 +2162,21 @@ ARRAY is a vector, string, char-table, or bool-vector. */) | |||
| 2161 | else if (STRINGP (array)) | 2162 | else if (STRINGP (array)) |
| 2162 | { | 2163 | { |
| 2163 | register unsigned char *p = SDATA (array); | 2164 | register unsigned char *p = SDATA (array); |
| 2164 | CHECK_NUMBER (item); | 2165 | int charval; |
| 2165 | charval = XINT (item); | 2166 | CHECK_CHARACTER (item); |
| 2167 | charval = XFASTINT (item); | ||
| 2166 | size = SCHARS (array); | 2168 | size = SCHARS (array); |
| 2167 | if (STRING_MULTIBYTE (array)) | 2169 | if (STRING_MULTIBYTE (array)) |
| 2168 | { | 2170 | { |
| 2169 | unsigned char str[MAX_MULTIBYTE_LENGTH]; | 2171 | unsigned char str[MAX_MULTIBYTE_LENGTH]; |
| 2170 | int len = CHAR_STRING (charval, str); | 2172 | int len = CHAR_STRING (charval, str); |
| 2171 | EMACS_INT size_byte = SBYTES (array); | 2173 | EMACS_INT size_byte = SBYTES (array); |
| 2172 | unsigned char *p1 = p, *endp = p + size_byte; | ||
| 2173 | int i; | ||
| 2174 | 2174 | ||
| 2175 | if (size != size_byte) | 2175 | if (INT_MULTIPLY_OVERFLOW (SCHARS (array), len) |
| 2176 | while (p1 < endp) | 2176 | || SCHARS (array) * len != size_byte) |
| 2177 | { | 2177 | error ("Attempt to change byte length of a string"); |
| 2178 | int this_len = BYTES_BY_CHAR_HEAD (*p1); | 2178 | for (idx = 0; idx < size_byte; idx++) |
| 2179 | if (len != this_len) | 2179 | *p++ = str[idx % len]; |
| 2180 | error ("Attempt to change byte length of a string"); | ||
| 2181 | p1 += this_len; | ||
| 2182 | } | ||
| 2183 | for (i = 0; i < size_byte; i++) | ||
| 2184 | *p++ = str[i % len]; | ||
| 2185 | } | 2180 | } |
| 2186 | else | 2181 | else |
| 2187 | for (idx = 0; idx < size; idx++) | 2182 | for (idx = 0; idx < size; idx++) |
| @@ -2190,19 +2185,18 @@ ARRAY is a vector, string, char-table, or bool-vector. */) | |||
| 2190 | else if (BOOL_VECTOR_P (array)) | 2185 | else if (BOOL_VECTOR_P (array)) |
| 2191 | { | 2186 | { |
| 2192 | register unsigned char *p = XBOOL_VECTOR (array)->data; | 2187 | register unsigned char *p = XBOOL_VECTOR (array)->data; |
| 2193 | int size_in_chars | 2188 | EMACS_INT size_in_chars; |
| 2194 | = ((XBOOL_VECTOR (array)->size + BOOL_VECTOR_BITS_PER_CHAR - 1) | 2189 | size = XBOOL_VECTOR (array)->size; |
| 2190 | size_in_chars | ||
| 2191 | = ((size + BOOL_VECTOR_BITS_PER_CHAR - 1) | ||
| 2195 | / BOOL_VECTOR_BITS_PER_CHAR); | 2192 | / BOOL_VECTOR_BITS_PER_CHAR); |
| 2196 | 2193 | ||
| 2197 | charval = (! NILP (item) ? -1 : 0); | 2194 | if (size_in_chars) |
| 2198 | for (idx = 0; idx < size_in_chars - 1; idx++) | ||
| 2199 | p[idx] = charval; | ||
| 2200 | if (idx < size_in_chars) | ||
| 2201 | { | 2195 | { |
| 2202 | /* Mask out bits beyond the vector size. */ | 2196 | memset (p, ! NILP (item) ? -1 : 0, size_in_chars); |
| 2203 | if (XBOOL_VECTOR (array)->size % BOOL_VECTOR_BITS_PER_CHAR) | 2197 | |
| 2204 | charval &= (1 << (XBOOL_VECTOR (array)->size % BOOL_VECTOR_BITS_PER_CHAR)) - 1; | 2198 | /* Clear any extraneous bits in the last byte. */ |
| 2205 | p[idx] = charval; | 2199 | p[size_in_chars - 1] &= (1 << (size % BOOL_VECTOR_BITS_PER_CHAR)) - 1; |
| 2206 | } | 2200 | } |
| 2207 | } | 2201 | } |
| 2208 | else | 2202 | else |
| @@ -2316,7 +2310,7 @@ mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq) | |||
| 2316 | { | 2310 | { |
| 2317 | for (i = 0; i < leni; i++) | 2311 | for (i = 0; i < leni; i++) |
| 2318 | { | 2312 | { |
| 2319 | int byte; | 2313 | unsigned char byte; |
| 2320 | byte = XBOOL_VECTOR (seq)->data[i / BOOL_VECTOR_BITS_PER_CHAR]; | 2314 | byte = XBOOL_VECTOR (seq)->data[i / BOOL_VECTOR_BITS_PER_CHAR]; |
| 2321 | dummy = (byte & (1 << (i % BOOL_VECTOR_BITS_PER_CHAR))) ? Qt : Qnil; | 2315 | dummy = (byte & (1 << (i % BOOL_VECTOR_BITS_PER_CHAR))) ? Qt : Qnil; |
| 2322 | dummy = call1 (fn, dummy); | 2316 | dummy = call1 (fn, dummy); |