summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-05-20 21:33:23 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2011-05-20 21:33:23 -0700
commitde883a701d8f0db9595c6c459fdff9e3bb20bc83 (patch)
treeaba160bb28d92c3fbec56549e211bd1f705b273e
parent1dcf791fefa6533a06f58a5d2d074f59f06ee9ae (diff)
downloademacs-de883a701d8f0db9595c6c459fdff9e3bb20bc83.tar.gz
emacs-de883a701d8f0db9595c6c459fdff9e3bb20bc83.tar.bz2
emacs-de883a701d8f0db9595c6c459fdff9e3bb20bc83.zip
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.
-rw-r--r--src/ChangeLog11
-rw-r--r--src/character.c9
-rw-r--r--src/character.h2
-rw-r--r--src/fns.c2
-rw-r--r--src/insdel.c31
-rw-r--r--src/lisp.h1
-rw-r--r--src/print.c2
7 files changed, 21 insertions, 37 deletions
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 <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
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);