aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 @@
12011-05-20 Paul Eggert <eggert@cs.ucla.edu>
2
3 merge count_size_as_multibyte, parse_str_to_multibyte
4 * character.c, character.h (count_size_as_multibyte):
5 Renamed from parse_str_to_multibyte; all uses changed.
6 Check for integer overflow.
7 * insdel.c, lisp.h (count_size_as_multibyte): Remove,
8 since it's now a duplicate of the other. This is more of
9 a character than a buffer op, so better that it's in character.c.
10 * fns.c, print.c: Adjust to above changes.
11
12011-05-20 Eli Zaretskii <eliz@gnu.org> 122011-05-20 Eli Zaretskii <eliz@gnu.org>
2 13
3 * callproc.c (Fcall_process) [MSDOS]: Fix arguments to 14 * 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,
672 `str_to_multibyte'. */ 672 `str_to_multibyte'. */
673 673
674EMACS_INT 674EMACS_INT
675parse_str_to_multibyte (const unsigned char *str, EMACS_INT len) 675count_size_as_multibyte (const unsigned char *str, EMACS_INT len)
676{ 676{
677 const unsigned char *endp = str + len; 677 const unsigned char *endp = str + len;
678 EMACS_INT bytes; 678 EMACS_INT bytes;
679 679
680 for (bytes = 0; str < endp; str++) 680 for (bytes = 0; str < endp; str++)
681 bytes += (*str < 0x80) ? 1 : 2; 681 {
682 int n = *str < 0x80 ? 1 : 2;
683 if (INT_ADD_OVERFLOW (bytes, n))
684 string_overflow ();
685 bytes += n;
686 }
682 return bytes; 687 return bytes;
683} 688}
684 689
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);
602extern int char_printable_p (int c); 602extern int char_printable_p (int c);
603extern void parse_str_as_multibyte (const unsigned char *, 603extern void parse_str_as_multibyte (const unsigned char *,
604 EMACS_INT, EMACS_INT *, EMACS_INT *); 604 EMACS_INT, EMACS_INT *, EMACS_INT *);
605extern EMACS_INT parse_str_to_multibyte (const unsigned char *, EMACS_INT); 605extern EMACS_INT count_size_as_multibyte (const unsigned char *, EMACS_INT);
606extern EMACS_INT str_as_multibyte (unsigned char *, EMACS_INT, EMACS_INT, 606extern EMACS_INT str_as_multibyte (unsigned char *, EMACS_INT, EMACS_INT,
607 EMACS_INT *); 607 EMACS_INT *);
608extern EMACS_INT str_to_multibyte (unsigned char *, EMACS_INT, EMACS_INT); 608extern 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)
898 if (STRING_MULTIBYTE (string)) 898 if (STRING_MULTIBYTE (string))
899 return string; 899 return string;
900 900
901 nbytes = parse_str_to_multibyte (SDATA (string), SBYTES (string)); 901 nbytes = count_size_as_multibyte (SDATA (string), SBYTES (string));
902 /* If all the chars are ASCII, they won't need any more bytes once 902 /* If all the chars are ASCII, they won't need any more bytes once
903 converted. */ 903 converted. */
904 if (nbytes == SBYTES (string)) 904 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,
570 return to_addr - initial_to_addr; 570 return to_addr - initial_to_addr;
571 } 571 }
572} 572}
573
574/* Return the number of bytes it would take
575 to convert some single-byte text to multibyte.
576 The single-byte text consists of NBYTES bytes at PTR. */
577
578EMACS_INT
579count_size_as_multibyte (const unsigned char *ptr, EMACS_INT nbytes)
580{
581 EMACS_INT i;
582 EMACS_INT outgoing_nbytes = 0;
583
584 for (i = 0; i < nbytes; i++)
585 {
586 unsigned int c = *ptr++;
587 int n;
588
589 if (ASCII_CHAR_P (c))
590 n = 1;
591 else
592 {
593 c = BYTE8_TO_CHAR (c);
594 n = CHAR_BYTES (c);
595 }
596
597 if (INT_ADD_OVERFLOW (outgoing_nbytes, n))
598 string_overflow ();
599 outgoing_nbytes += n;
600 }
601
602 return outgoing_nbytes;
603}
604 573
605/* Insert a string of specified length before point. 574/* Insert a string of specified length before point.
606 This function judges multibyteness based on 575 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);
2574extern void make_gap (EMACS_INT); 2574extern void make_gap (EMACS_INT);
2575extern EMACS_INT copy_text (const unsigned char *, unsigned char *, 2575extern EMACS_INT copy_text (const unsigned char *, unsigned char *,
2576 EMACS_INT, int, int); 2576 EMACS_INT, int, int);
2577extern EMACS_INT count_size_as_multibyte (const unsigned char *, EMACS_INT);
2578extern int count_combining_before (const unsigned char *, 2577extern int count_combining_before (const unsigned char *,
2579 EMACS_INT, EMACS_INT, EMACS_INT); 2578 EMACS_INT, EMACS_INT, EMACS_INT);
2580extern int count_combining_after (const unsigned char *, 2579extern 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)
381 EMACS_INT bytes; 381 EMACS_INT bytes;
382 382
383 chars = SBYTES (string); 383 chars = SBYTES (string);
384 bytes = parse_str_to_multibyte (SDATA (string), chars); 384 bytes = count_size_as_multibyte (SDATA (string), chars);
385 if (chars < bytes) 385 if (chars < bytes)
386 { 386 {
387 newstr = make_uninit_multibyte_string (chars, bytes); 387 newstr = make_uninit_multibyte_string (chars, bytes);