diff options
author | Eli Zaretskii <eliz@gnu.org> | 2010-09-23 08:09:12 -0400 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2010-09-23 08:09:12 -0400 |
commit | 141624691330c7622d9a31d53ec919dee8e97473 (patch) | |
tree | c8f2a43e69346342552c6a72a307555ae26a739f /src/character.c | |
parent | 7228f056909af1ffe9d8f611b959638bc9544d2f (diff) | |
download | emacs-141624691330c7622d9a31d53ec919dee8e97473.tar.gz |
Fix some more uses of int instead of EMACS_INT.
font.c (font_intern_prop): Use EMACS_INT for string length
variables.
character.c (parse_str_as_multibyte, str_as_multibyte)
(parse_str_to_multibyte, str_to_multibyte, str_as_unibyte)
(string_count_byte8, string_escape_byte8): Use EMACS_INT for
string length arguments, variables, and return values.
character.h (parse_str_as_multibyte, str_as_multibyte)
(parse_str_to_multibyte, str_to_multibyte, str_as_unibyte): Adjust
prototypes.
fns.c (Fstring_as_multibyte): Use EMACS_INT for string length
variables.
alloc.c <total_string_size>: Declare as EMACS_INT, not int.
(Fmake_string): Protect against too large strings.
(live_string_p, live_cons_p, live_symbol_p, live_float_p)
(live_misc_p): Use ptrdiff_t instead of int for pointer
differences.
(string_bytes, check_sblock, check_string_free_list)
(allocate_string_data, compact_small_strings, Fmake_string)
(Fmake_bool_vector, make_string, make_unibyte_string)
(make_multibyte_string, make_string_from_bytes)
(make_specified_string_string, Fmake_list, Fmake_vector): Use
EMACS_INT for string length variables and arguments.
(find_string_data_in_pure, make_pure_string, make_pure_c_string)
(Fpurecopy): Use EMACS_INT for string size.
(mark_vectorlike, mark_char_table, mark_object): Use EMACS_UINT
for vector size.
lisp.h (make_string, make_unibyte_string, make_multibyte_string)
(make_string_from_bytes, make_specified_string_string)
(make_pure_string, string_bytes): Adjust prototypes.
Diffstat (limited to 'src/character.c')
-rw-r--r-- | src/character.c | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/src/character.c b/src/character.c index c4a3a008bcd..90f6be10067 100644 --- a/src/character.c +++ b/src/character.c @@ -592,10 +592,11 @@ multibyte_chars_in_text (const unsigned char *ptr, EMACS_INT nbytes) represented by 2-byte in a multibyte text. */ void -parse_str_as_multibyte (const unsigned char *str, int len, int *nchars, int *nbytes) +parse_str_as_multibyte (const unsigned char *str, EMACS_INT len, + EMACS_INT *nchars, EMACS_INT *nbytes) { const unsigned char *endp = str + len; - int n, chars = 0, bytes = 0; + EMACS_INT n, chars = 0, bytes = 0; if (len >= MAX_MULTIBYTE_LENGTH) { @@ -633,12 +634,13 @@ parse_str_as_multibyte (const unsigned char *str, int len, int *nchars, int *nby area and that is enough. Return the number of bytes of the resulting text. */ -int -str_as_multibyte (unsigned char *str, int len, int nbytes, int *nchars) +EMACS_INT +str_as_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT nbytes, + EMACS_INT *nchars) { unsigned char *p = str, *endp = str + nbytes; unsigned char *to; - int chars = 0; + EMACS_INT chars = 0; int n; if (nbytes >= MAX_MULTIBYTE_LENGTH) @@ -709,11 +711,11 @@ str_as_multibyte (unsigned char *str, int len, int nbytes, int *nchars) bytes it may ocupy when converted to multibyte string by `str_to_multibyte'. */ -int -parse_str_to_multibyte (const unsigned char *str, int len) +EMACS_INT +parse_str_to_multibyte (const unsigned char *str, EMACS_INT len) { const unsigned char *endp = str + len; - int bytes; + EMACS_INT bytes; for (bytes = 0; str < endp; str++) bytes += (*str < 0x80) ? 1 : 2; @@ -727,8 +729,8 @@ parse_str_to_multibyte (const unsigned char *str, int len) that we can use LEN bytes at STR as a work area and that is enough. */ -int -str_to_multibyte (unsigned char *str, int len, int bytes) +EMACS_INT +str_to_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT bytes) { unsigned char *p = str, *endp = str + bytes; unsigned char *to; @@ -756,8 +758,8 @@ str_to_multibyte (unsigned char *str, int len, int bytes) actually converts characters in the range 0x80..0xFF to unibyte. */ -int -str_as_unibyte (unsigned char *str, int bytes) +EMACS_INT +str_as_unibyte (unsigned char *str, EMACS_INT bytes) { const unsigned char *p = str, *endp = str + bytes; unsigned char *to; @@ -818,14 +820,14 @@ str_to_unibyte (const unsigned char *src, unsigned char *dst, EMACS_INT chars, i } -int +EMACS_INT string_count_byte8 (Lisp_Object string) { int multibyte = STRING_MULTIBYTE (string); - int nbytes = SBYTES (string); + EMACS_INT nbytes = SBYTES (string); unsigned char *p = SDATA (string); unsigned char *pend = p + nbytes; - int count = 0; + EMACS_INT count = 0; int c, len; if (multibyte) @@ -851,10 +853,10 @@ string_count_byte8 (Lisp_Object string) Lisp_Object string_escape_byte8 (Lisp_Object string) { - int nchars = SCHARS (string); - int nbytes = SBYTES (string); + EMACS_INT nchars = SCHARS (string); + EMACS_INT nbytes = SBYTES (string); int multibyte = STRING_MULTIBYTE (string); - int byte8_count; + EMACS_INT byte8_count; const unsigned char *src, *src_end; unsigned char *dst; Lisp_Object val; @@ -869,12 +871,22 @@ string_escape_byte8 (Lisp_Object string) return string; if (multibyte) - /* Convert 2-byte sequence of byte8 chars to 4-byte octal. */ - val = make_uninit_multibyte_string (nchars + byte8_count * 3, - nbytes + byte8_count * 2); + { + if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count + || (MOST_POSITIVE_FIXNUM - nbytes) / 2 < byte8_count) + error ("Maximum string size exceeded"); + + /* Convert 2-byte sequence of byte8 chars to 4-byte octal. */ + val = make_uninit_multibyte_string (nchars + byte8_count * 3, + nbytes + byte8_count * 2); + } else - /* Convert 1-byte sequence of byte8 chars to 4-byte octal. */ - val = make_uninit_string (nbytes + byte8_count * 3); + { + if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count) + error ("Maximum string size exceeded"); + /* Convert 1-byte sequence of byte8 chars to 4-byte octal. */ + val = make_uninit_string (nbytes + byte8_count * 3); + } src = SDATA (string); src_end = src + nbytes; |