From: Paul Eggert Date: Sat, 21 May 2011 04:33:23 +0000 (-0700) Subject: merge count_size_as_multibyte, parse_str_to_multibyte X-Git-Tag: emacs-pretest-24.0.90~104^2~618^2~139^2~15 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=de883a701d8f0db9595c6c459fdff9e3bb20bc83;p=emacs.git merge count_size_as_multibyte, parse_str_to_multibyte * character.c, character.h (count_size_as_multibyte): Renamed from parse_str_to_multibyte; all uses changed. Check for integer overflow. * insdel.c, lisp.h (count_size_as_multibyte): Remove, since it's now a duplicate of the other. This is more of a character than a buffer op, so better that it's in character.c. * fns.c, print.c: Adjust to above changes. --- diff --git a/src/ChangeLog b/src/ChangeLog index bef6c1593a7..8bd4426781d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2011-05-20 Paul Eggert + + merge count_size_as_multibyte, parse_str_to_multibyte + * character.c, character.h (count_size_as_multibyte): + Renamed from parse_str_to_multibyte; all uses changed. + Check for integer overflow. + * insdel.c, lisp.h (count_size_as_multibyte): Remove, + since it's now a duplicate of the other. This is more of + a character than a buffer op, so better that it's in character.c. + * fns.c, print.c: Adjust to above changes. + 2011-05-20 Eli Zaretskii * callproc.c (Fcall_process) [MSDOS]: Fix arguments to diff --git a/src/character.c b/src/character.c index b9595f97ec7..34e69da9cc5 100644 --- a/src/character.c +++ b/src/character.c @@ -672,13 +672,18 @@ str_as_multibyte (unsigned char *str, EMACS_INT len, EMACS_INT nbytes, `str_to_multibyte'. */ EMACS_INT -parse_str_to_multibyte (const unsigned char *str, EMACS_INT len) +count_size_as_multibyte (const unsigned char *str, EMACS_INT len) { const unsigned char *endp = str + len; EMACS_INT bytes; for (bytes = 0; str < endp; str++) - bytes += (*str < 0x80) ? 1 : 2; + { + int n = *str < 0x80 ? 1 : 2; + if (INT_ADD_OVERFLOW (bytes, n)) + string_overflow (); + bytes += n; + } return bytes; } diff --git a/src/character.h b/src/character.h index 5877d145d9e..31e3b0a9416 100644 --- a/src/character.h +++ b/src/character.h @@ -602,7 +602,7 @@ extern int translate_char (Lisp_Object, int c); extern int char_printable_p (int c); extern void parse_str_as_multibyte (const unsigned char *, EMACS_INT, EMACS_INT *, EMACS_INT *); -extern EMACS_INT parse_str_to_multibyte (const unsigned char *, EMACS_INT); +extern EMACS_INT count_size_as_multibyte (const unsigned char *, EMACS_INT); extern EMACS_INT str_as_multibyte (unsigned char *, EMACS_INT, EMACS_INT, EMACS_INT *); extern EMACS_INT str_to_multibyte (unsigned char *, EMACS_INT, EMACS_INT); diff --git a/src/fns.c b/src/fns.c index 16dc0fe0de2..d61c1ac7ba9 100644 --- a/src/fns.c +++ b/src/fns.c @@ -898,7 +898,7 @@ string_to_multibyte (Lisp_Object string) if (STRING_MULTIBYTE (string)) return string; - nbytes = parse_str_to_multibyte (SDATA (string), SBYTES (string)); + nbytes = count_size_as_multibyte (SDATA (string), SBYTES (string)); /* If all the chars are ASCII, they won't need any more bytes once converted. */ if (nbytes == SBYTES (string)) diff --git a/src/insdel.c b/src/insdel.c index de9e8aa570a..c0cccc65d6a 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -570,37 +570,6 @@ copy_text (const unsigned char *from_addr, unsigned char *to_addr, return to_addr - initial_to_addr; } } - -/* Return the number of bytes it would take - to convert some single-byte text to multibyte. - The single-byte text consists of NBYTES bytes at PTR. */ - -EMACS_INT -count_size_as_multibyte (const unsigned char *ptr, EMACS_INT nbytes) -{ - EMACS_INT i; - EMACS_INT outgoing_nbytes = 0; - - for (i = 0; i < nbytes; i++) - { - unsigned int c = *ptr++; - int n; - - if (ASCII_CHAR_P (c)) - n = 1; - else - { - c = BYTE8_TO_CHAR (c); - n = CHAR_BYTES (c); - } - - if (INT_ADD_OVERFLOW (outgoing_nbytes, n)) - string_overflow (); - outgoing_nbytes += n; - } - - return outgoing_nbytes; -} /* Insert a string of specified length before point. This function judges multibyteness based on diff --git a/src/lisp.h b/src/lisp.h index b6bf2bdb502..b2beeffa79e 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -2574,7 +2574,6 @@ extern void move_gap_both (EMACS_INT, EMACS_INT); extern void make_gap (EMACS_INT); extern EMACS_INT copy_text (const unsigned char *, unsigned char *, EMACS_INT, int, int); -extern EMACS_INT count_size_as_multibyte (const unsigned char *, EMACS_INT); extern int count_combining_before (const unsigned char *, EMACS_INT, EMACS_INT, EMACS_INT); extern int count_combining_after (const unsigned char *, diff --git a/src/print.c b/src/print.c index f0624d5d16e..20c3e8ae526 100644 --- a/src/print.c +++ b/src/print.c @@ -381,7 +381,7 @@ print_string (Lisp_Object string, Lisp_Object printcharfun) EMACS_INT bytes; chars = SBYTES (string); - bytes = parse_str_to_multibyte (SDATA (string), chars); + bytes = count_size_as_multibyte (SDATA (string), chars); if (chars < bytes) { newstr = make_uninit_multibyte_string (chars, bytes);