mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-16 09:50:25 +00:00
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.
This commit is contained in:
parent
1dcf791fef
commit
de883a701d
@ -1,3 +1,14 @@
|
||||
2011-05-20 Paul Eggert <eggert@cs.ucla.edu>
|
||||
|
||||
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 <eliz@gnu.org>
|
||||
|
||||
* callproc.c (Fcall_process) [MSDOS]: Fix arguments to
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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))
|
||||
|
31
src/insdel.c
31
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
|
||||
|
@ -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 *,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user