changeset 110503:fda36a325177

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.
author Eli Zaretskii <eliz@gnu.org>
date Thu, 23 Sep 2010 08:09:12 -0400
parents 10e44274dbb4
children 0fdd992ff057
files src/ChangeLog src/alloc.c src/character.c src/character.h src/fns.c src/font.c src/lisp.h
diffstat 7 files changed, 138 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Sep 23 07:59:12 2010 +0000
+++ b/src/ChangeLog	Thu Sep 23 08:09:12 2010 -0400
@@ -1,3 +1,40 @@
+2010-09-23  Eli Zaretskii  <eliz@gnu.org>
+
+	* 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.
+
 2010-09-22  Eli Zaretskii  <eliz@gnu.org>
 
 	* editfns.c (Fsubst_char_in_region, Ftranslate_region_internal)
--- a/src/alloc.c	Thu Sep 23 07:59:12 2010 +0000
+++ b/src/alloc.c	Thu Sep 23 08:09:12 2010 -0400
@@ -1644,7 +1644,7 @@
 
 /* Number of bytes used by live strings.  */
 
-static int total_string_size;
+static EMACS_INT total_string_size;
 
 /* Given a pointer to a Lisp_String S which is on the free-list
    string_free_list, return a pointer to its successor in the
@@ -1739,11 +1739,12 @@
 
 /* Like GC_STRING_BYTES, but with debugging check.  */
 
-int
-string_bytes (s)
-     struct Lisp_String *s;
+EMACS_INT
+string_bytes (struct Lisp_String *s)
 {
-  int nbytes = (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte);
+  EMACS_INT nbytes =
+    (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte);
+
   if (!PURE_POINTER_P (s)
       && s->data
       && nbytes != SDATA_NBYTES (SDATA_OF_STRING (s)))
@@ -1765,7 +1766,7 @@
     {
       /* Compute the next FROM here because copying below may
 	 overwrite data we need to compute it.  */
-      int nbytes;
+      EMACS_INT nbytes;
 
       /* Check that the string size recorded in the string is the
 	 same as the one recorded in the sdata structure. */
@@ -1825,7 +1826,7 @@
   s = string_free_list;
   while (s != NULL)
     {
-      if ((unsigned)s < 1024)
+      if ((unsigned long)s < 1024)
 	abort();
       s = NEXT_FREE_LISP_STRING (s);
     }
@@ -1913,7 +1914,7 @@
 {
   struct sdata *data, *old_data;
   struct sblock *b;
-  int needed, old_nbytes;
+  EMACS_INT needed, old_nbytes;
 
   /* Determine the number of bytes needed to store NBYTES bytes
      of string data.  */
@@ -2155,7 +2156,7 @@
 	{
 	  /* Compute the next FROM here because copying below may
 	     overwrite data we need to compute it.  */
-	  int nbytes;
+	  EMACS_INT nbytes;
 
 #ifdef GC_CHECK_STRING_BYTES
 	  /* Check that the string size recorded in the string is the
@@ -2233,7 +2234,8 @@
 {
   register Lisp_Object val;
   register unsigned char *p, *end;
-  int c, nbytes;
+  int c;
+  EMACS_INT nbytes;
 
   CHECK_NATNUM (length);
   CHECK_NUMBER (init);
@@ -2252,9 +2254,12 @@
     {
       unsigned char str[MAX_MULTIBYTE_LENGTH];
       int len = CHAR_STRING (c, str);
-
-      nbytes = len * XINT (length);
-      val = make_uninit_multibyte_string (XINT (length), nbytes);
+      EMACS_INT string_len = XINT (length);
+
+      if (string_len > MOST_POSITIVE_FIXNUM / len)
+	error ("Maximum string size exceeded");
+      nbytes = len * string_len;
+      val = make_uninit_multibyte_string (string_len, nbytes);
       p = SDATA (val);
       end = p + nbytes;
       while (p != end)
@@ -2277,7 +2282,8 @@
   register Lisp_Object val;
   struct Lisp_Bool_Vector *p;
   int real_init, i;
-  int length_in_chars, length_in_elts, bits_per_value;
+  EMACS_INT length_in_chars, length_in_elts;
+  int bits_per_value;
 
   CHECK_NATNUM (length);
 
@@ -2317,10 +2323,10 @@
    multibyte, depending on the contents.  */
 
 Lisp_Object
-make_string (const char *contents, int nbytes)
+make_string (const char *contents, EMACS_INT nbytes)
 {
   register Lisp_Object val;
-  int nchars, multibyte_nbytes;
+  EMACS_INT nchars, multibyte_nbytes;
 
   parse_str_as_multibyte (contents, nbytes, &nchars, &multibyte_nbytes);
   if (nbytes == nchars || nbytes != multibyte_nbytes)
@@ -2336,7 +2342,7 @@
 /* Make an unibyte string from LENGTH bytes at CONTENTS.  */
 
 Lisp_Object
-make_unibyte_string (const char *contents, int length)
+make_unibyte_string (const char *contents, EMACS_INT length)
 {
   register Lisp_Object val;
   val = make_uninit_string (length);
@@ -2350,7 +2356,8 @@
    bytes at CONTENTS.  */
 
 Lisp_Object
-make_multibyte_string (const char *contents, int nchars, int nbytes)
+make_multibyte_string (const char *contents,
+		       EMACS_INT nchars, EMACS_INT nbytes)
 {
   register Lisp_Object val;
   val = make_uninit_multibyte_string (nchars, nbytes);
@@ -2363,7 +2370,8 @@
    CONTENTS.  It is a multibyte string if NBYTES != NCHARS.  */
 
 Lisp_Object
-make_string_from_bytes (const char *contents, int nchars, int nbytes)
+make_string_from_bytes (const char *contents,
+			EMACS_INT nchars, EMACS_INT nbytes)
 {
   register Lisp_Object val;
   val = make_uninit_multibyte_string (nchars, nbytes);
@@ -2380,7 +2388,8 @@
    characters by itself.  */
 
 Lisp_Object
-make_specified_string (const char *contents, int nchars, int nbytes, int multibyte)
+make_specified_string (const char *contents,
+		       EMACS_INT nchars, EMACS_INT nbytes, int multibyte)
 {
   register Lisp_Object val;
 
@@ -2768,7 +2777,7 @@
   (register Lisp_Object length, Lisp_Object init)
 {
   register Lisp_Object val;
-  register int size;
+  register EMACS_INT size;
 
   CHECK_NATNUM (length);
   size = XFASTINT (length);
@@ -2946,7 +2955,7 @@
 {
   Lisp_Object vector;
   register EMACS_INT sizei;
-  register int index;
+  register EMACS_INT index;
   register struct Lisp_Vector *p;
 
   CHECK_NATNUM (length);
@@ -3786,7 +3795,7 @@
   if (m->type == MEM_TYPE_STRING)
     {
       struct string_block *b = (struct string_block *) m->start;
-      int offset = (char *) p - (char *) &b->strings[0];
+      ptrdiff_t offset = (char *) p - (char *) &b->strings[0];
 
       /* P must point to the start of a Lisp_String structure, and it
 	 must not be on the free-list.  */
@@ -3809,7 +3818,7 @@
   if (m->type == MEM_TYPE_CONS)
     {
       struct cons_block *b = (struct cons_block *) m->start;
-      int offset = (char *) p - (char *) &b->conses[0];
+      ptrdiff_t offset = (char *) p - (char *) &b->conses[0];
 
       /* P must point to the start of a Lisp_Cons, not be
 	 one of the unused cells in the current cons block,
@@ -3835,7 +3844,7 @@
   if (m->type == MEM_TYPE_SYMBOL)
     {
       struct symbol_block *b = (struct symbol_block *) m->start;
-      int offset = (char *) p - (char *) &b->symbols[0];
+      ptrdiff_t offset = (char *) p - (char *) &b->symbols[0];
 
       /* P must point to the start of a Lisp_Symbol, not be
 	 one of the unused cells in the current symbol block,
@@ -3861,7 +3870,7 @@
   if (m->type == MEM_TYPE_FLOAT)
     {
       struct float_block *b = (struct float_block *) m->start;
-      int offset = (char *) p - (char *) &b->floats[0];
+      ptrdiff_t offset = (char *) p - (char *) &b->floats[0];
 
       /* P must point to the start of a Lisp_Float and not be
 	 one of the unused cells in the current float block.  */
@@ -3885,7 +3894,7 @@
   if (m->type == MEM_TYPE_MISC)
     {
       struct marker_block *b = (struct marker_block *) m->start;
-      int offset = (char *) p - (char *) &b->markers[0];
+      ptrdiff_t offset = (char *) p - (char *) &b->markers[0];
 
       /* P must point to the start of a Lisp_Misc, not be
 	 one of the unused cells in the current misc block,
@@ -4592,9 +4601,10 @@
    address.  Return NULL if not found.  */
 
 static char *
-find_string_data_in_pure (const char *data, int nbytes)
+find_string_data_in_pure (const char *data, EMACS_INT nbytes)
 {
-  int i, skip, bm_skip[256], last_char_skip, infinity, start, start_max;
+  int i;
+  EMACS_INT skip, bm_skip[256], last_char_skip, infinity, start, start_max;
   const unsigned char *p;
   char *non_lisp_beg;
 
@@ -4661,7 +4671,8 @@
    string; then the string is not protected from gc.  */
 
 Lisp_Object
-make_pure_string (const char *data, int nchars, int nbytes, int multibyte)
+make_pure_string (const char *data,
+		  EMACS_INT nchars, EMACS_INT nbytes, int multibyte)
 {
   Lisp_Object string;
   struct Lisp_String *s;
@@ -4689,7 +4700,7 @@
 {
   Lisp_Object string;
   struct Lisp_String *s;
-  int nchars = strlen (data);
+  EMACS_INT nchars = strlen (data);
 
   s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
   s->size = nchars;
@@ -4779,7 +4790,7 @@
   else if (COMPILEDP (obj) || VECTORP (obj))
     {
       register struct Lisp_Vector *vec;
-      register int i;
+      register EMACS_INT i;
       EMACS_INT size;
 
       size = XVECTOR (obj)->size;
@@ -5228,8 +5239,8 @@
 static void
 mark_vectorlike (struct Lisp_Vector *ptr)
 {
-  register EMACS_INT size = ptr->size;
-  register int i;
+  register EMACS_UINT size = ptr->size;
+  register EMACS_UINT i;
 
   eassert (!VECTOR_MARKED_P (ptr));
   VECTOR_MARK (ptr);		/* Else mark it */
@@ -5251,8 +5262,8 @@
 static void
 mark_char_table (struct Lisp_Vector *ptr)
 {
-  register EMACS_INT size = ptr->size & PSEUDOVECTOR_SIZE_MASK;
-  register int i;
+  register EMACS_UINT size = ptr->size & PSEUDOVECTOR_SIZE_MASK;
+  register EMACS_UINT i;
 
   eassert (!VECTOR_MARKED_P (ptr));
   VECTOR_MARK (ptr);
@@ -5381,8 +5392,8 @@
 	   recursion there.  */
 	{
 	  register struct Lisp_Vector *ptr = XVECTOR (obj);
-	  register EMACS_INT size = ptr->size;
-	  register int i;
+	  register EMACS_UINT size = ptr->size;
+	  register EMACS_UINT i;
 
 	  CHECK_LIVE (live_vector_p);
 	  VECTOR_MARK (ptr);	/* Else mark it */
--- a/src/character.c	Thu Sep 23 07:59:12 2010 +0000
+++ b/src/character.c	Thu Sep 23 08:09:12 2010 -0400
@@ -592,10 +592,11 @@
    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 @@
    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 @@
    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 @@
    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 @@
    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 @@
 }
 
 
-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 @@
 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 @@
     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;
--- a/src/character.h	Thu Sep 23 07:59:12 2010 +0000
+++ b/src/character.h	Thu Sep 23 08:09:12 2010 -0400
@@ -603,12 +603,13 @@
 
 extern int translate_char (Lisp_Object, int c);
 extern int char_printable_p (int c);
-extern void parse_str_as_multibyte (const unsigned char *, int, int *,
-                                    int *);
-extern int parse_str_to_multibyte (const unsigned char *, int);
-extern int str_as_multibyte (unsigned char *, int, int, int *);
-extern int str_to_multibyte (unsigned char *, int, int);
-extern int str_as_unibyte (unsigned char *, int);
+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 str_as_multibyte (unsigned char *, EMACS_INT, EMACS_INT,
+			     EMACS_INT *);
+extern EMACS_INT str_to_multibyte (unsigned char *, EMACS_INT, EMACS_INT);
+extern EMACS_INT str_as_unibyte (unsigned char *, EMACS_INT);
 extern EMACS_INT str_to_unibyte (const unsigned char *, unsigned char *,
                                  EMACS_INT, int);
 extern int strwidth (const unsigned char *, int);
--- a/src/fns.c	Thu Sep 23 07:59:12 2010 +0000
+++ b/src/fns.c	Thu Sep 23 08:09:12 2010 -0400
@@ -1036,7 +1036,7 @@
   if (! STRING_MULTIBYTE (string))
     {
       Lisp_Object new_string;
-      int nchars, nbytes;
+      EMACS_INT nchars, nbytes;
 
       parse_str_as_multibyte (SDATA (string),
 			      SBYTES (string),
--- a/src/font.c	Thu Sep 23 07:59:12 2010 +0000
+++ b/src/font.c	Thu Sep 23 08:09:12 2010 -0400
@@ -237,7 +237,7 @@
   int i;
   Lisp_Object tem;
   Lisp_Object obarray;
-  int nbytes, nchars;
+  EMACS_INT nbytes, nchars;
 
   if (len == 1 && *str == '*')
     return Qnil;
--- a/src/lisp.h	Thu Sep 23 07:59:12 2010 +0000
+++ b/src/lisp.h	Thu Sep 23 08:09:12 2010 -0400
@@ -739,7 +739,7 @@
 #ifdef GC_CHECK_STRING_BYTES
 
 struct Lisp_String;
-extern int string_bytes (struct Lisp_String *);
+extern EMACS_INT string_bytes (struct Lisp_String *);
 #define STRING_BYTES(S) string_bytes ((S))
 
 #else /* not GC_CHECK_STRING_BYTES */
@@ -2718,16 +2718,17 @@
 EXFUN (Fmake_marker, 0);
 EXFUN (Fmake_string, 2);
 extern Lisp_Object build_string (const char *);
-extern Lisp_Object make_string (const char *, int);
-extern Lisp_Object make_unibyte_string (const char *, int);
-extern Lisp_Object make_multibyte_string (const char *, int, int);
+extern Lisp_Object make_string (const char *, EMACS_INT);
+extern Lisp_Object make_unibyte_string (const char *, EMACS_INT);
+extern Lisp_Object make_multibyte_string (const char *, EMACS_INT, EMACS_INT);
 extern Lisp_Object make_event_array (int, Lisp_Object *);
 extern Lisp_Object make_uninit_string (EMACS_INT);
 extern Lisp_Object make_uninit_multibyte_string (EMACS_INT, EMACS_INT);
-extern Lisp_Object make_string_from_bytes (const char *, int, int);
-extern Lisp_Object make_specified_string (const char *, int, int, int);
+extern Lisp_Object make_string_from_bytes (const char *, EMACS_INT, EMACS_INT);
+extern Lisp_Object make_specified_string (const char *,
+					  EMACS_INT, EMACS_INT, int);
 EXFUN (Fpurecopy, 1);
-extern Lisp_Object make_pure_string (const char *, int, int, int);
+extern Lisp_Object make_pure_string (const char *, EMACS_INT, EMACS_INT, int);
 extern Lisp_Object make_pure_c_string (const char *data);
 extern Lisp_Object pure_cons (Lisp_Object, Lisp_Object);
 extern Lisp_Object make_pure_vector (EMACS_INT);