APPROVE COMMIT
NOTE: This patch has been committed
# HG changeset patch
# User Aidan Kehoe <kehoea(a)parhasard.net>
# Date 1524487420 -3600
#      Mon Apr 23 13:43:40 2018 +0100
# Node ID c5889f9bb7f42149ee575ea6553eebe24a2652b8
# Parent  046a3f85a39d07ff8186173630a42b06eb1ec1f5
Quiet warnings with -Wnarrowing, GCC, improving quality on 64 bit builds
src/ChangeLog addition:
2018-04-23  Aidan Kehoe  <kehoea(a)parhasard.net>
	* abbrev.c (Fexpand_abbrev):
	* alloc.c (struct):
	* alloc.c (malloc_after):
	* alloc.c (xmalloc):
	* alloc.c (xcalloc):
	* alloc.c (xrealloc):
	* alloc.c (xstrdup):
	* alloc.c (alloc_sized_lrecord_1):
	* alloc.c (alloc_sized_lrecord_array):
	* alloc.c (alloc_lrecord_array):
	* alloc.c (copy_lisp_object):
	* alloc.c (dbg_inhibit_dbg_symbol_deletion):
	* alloc.c (make_uninit_vector):
	* alloc.c (Fvector):
	* alloc.c (bit_vector_equal):
	* alloc.c (make_bit_vector):
	* alloc.c (string_equal):
	* alloc.c (resize_string):
	* alloc.c (set_string_char):
	* alloc.c (Fmake_string):
	* alloc.c (Fstring):
	* alloc.c (init_string_ascii_begin):
	* alloc.c (make_string):
	* alloc.c (dec_lrecord_stats):
	* alloc.c (lrecord_stats_heap_size):
	* alloc.c (pluralize_word):
	* array.c (Dynarr_realloc):
	* array.c (Dynarr_insert_many):
	* array.c (Dynarr_delete_many):
	* array.c (gap_array_move_gap):
	* array.h:
	* array.h (Dynarr_declare):
	* array.h (Dynarr_delete_object):
	* array.h (gap_array_marker):
	* buffer.c (MARKED_SLOT):
	* buffer.c (Fgenerate_new_buffer_name):
	* buffer.c (DEFVAR_BUFFER_LOCAL_1):
	* buffer.h (struct buffer):
	* bytecode.c (make_compiled_function_args):
	* bytecode.c (UNUSED):
	* callint.c (Fcall_interactively):
	* casefiddle.c (casify_object):
	* casefiddle.c (casify_region_internal):
	* charset.h:
	* chartab.c (clone_chartab_table):
	* chartab.c (put_char_table):
	* chartab.c (decode_char_table_range):
	* cmds.c (Fpoint_at_bol):
	* cmds.c (Fpoint_at_eol):
	* cmds.c (internal_self_insert):
	* console.c (delete_console_internal):
	* console.c (Fset_input_mode):
	* console.c (DEFVAR_CONSOLE_LOCAL_1):
	* console.h:
	* data.c (lisp_to_uint32_t):
	* data.c (lisp_to_int32_t):
	* data.c (rem_two_fixnum):
	* data.c (Flsh):
	* debug.c (FROB):
	* device.c (Fmake_device):
	* device.c (delete_device_internal):
	* device.c (Fset_device_baud_rate):
	* device.h:
	* doc.c (extract_object_file_name):
	* doc.c (Fsnarf_documentation):
	* doc.c (verify_doc_mapper):
	* doc.c (Fsubstitute_command_keys):
	* doprnt.c (Fnumber_to_string):
	* doprnt.c (emacs_doprnt):
	* editfns.c (Finsert_char):
	* editfns.c (save_restriction_restore):
	* elhash.c (internal_array_hash):
	* filelock.c (LOCK_PID_MAX):
	* filelock.c (fill_in_lock_file_name):
	* filelock.c (current_lock_owner):
	* indent.c:
	* indent.c (column_at_point):
	* indent.c (string_column_at_point):
	* indent.c (current_column):
	* indent.c (Findent_to):
	* indent.c (byte_spaces_at_point):
	* indent.c (Fmove_to_column):
	* indent.c (Fcompute_motion):
	* indent.c (vertical_motion_1):
	* indent.c (Fvertical_motion_pixels):
	* lisp-disunion.h (XCHARVAL):
	* lisp-disunion.h (wrap_pointer_1):
	* lisp.h:
	* lisp.h (ALLOCA):
	* lisp.h (XSET_STRING_ASCII_BEGIN):
	* lisp.h (CHECK_CHAR_COERCE_INT):
	* lisp.h (LISP_HASH):
	* lisp.h (struct gcpro):
	* lisp.h (DECLARE_INLINE_HEADER):
	* lrecord.h:
	* lrecord.h (set_lheader_implementation):
	* number.h:
	* number.h (integer_signum):
	* number.h (NATNUMP):
	* print.c (debug_short_backtrace):
	* search.c (find_before_next_newline):
	* syntax.c (scan_words):
	* syntax.h:
	* sysdep.c:
	* sysdep.c (wait_for_termination):
	* sysdep.c (sys_subshell):
	* sysdep.c (sys_suspend):
	* sysdep.c (init_sigio_on_device):
	* sysdep.c (qxe_readlink):
	* sysfile.h:
	* text.c (eifind_large_enough_buffer):
	* text.h:
	* text.h (ASSERT_ASCTEXT_ASCII_LEN):
	* text.h (struct):
	* text.h (EI_ALLOC):
	* text.h (eicpy_lstr_off):
	* text.h (eicpy_raw_fmt):
	* text.h (eicpy_ascii_len):
	* text.h (eicpy_ext_len):
	* text.h (eimake_string_off):
	* text.h (DECLARE_INLINE_HEADER):
	* text.h (eicat_1):
	* text.h (eicat_ascii):
	* text.h (eicat_raw):
	* text.h (eisub_1):
	* text.h (eisub_ascii):
	* text.h (EI_CASECHANGE):
	* undo.c (truncate_undo_list):
	* unicode.c (print_precedence_array):
	Be more careful about integer types within the C code, e.g. not
	using an int where a value represents a (possibly large) number of
	bytes, or characters, especially relevant for values like fill
	columns, which can usefully be set to most-positive-fixnum,
	something the code up to now dealt with badly on a 64-bit build.
	Issues flushed out using the -Wnarrowing GCC option.
	* lisp.h (XCHAR_OR_CHAR_INT):
	Provide an error-checking version of this to check uses with
	fixnums where valid_ichar_p() is not true.
	* lisp.h (GOOD_HASH):
	Set this to a prime number just over 2^32 on sixty-four bit
	architectures, of type Hashcode, an unsigned type, so modular
	arithmetic is defined.
diff -r 046a3f85a39d -r c5889f9bb7f4 src/ChangeLog
--- a/src/ChangeLog	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/ChangeLog	Mon Apr 23 13:43:40 2018 +0100
@@ -1,3 +1,150 @@
+2018-04-23  Aidan Kehoe  <kehoea(a)parhasard.net>
+
+	* abbrev.c (Fexpand_abbrev):
+	* alloc.c (struct):
+	* alloc.c (malloc_after):
+	* alloc.c (xmalloc):
+	* alloc.c (xcalloc):
+	* alloc.c (xrealloc):
+	* alloc.c (xstrdup):
+	* alloc.c (alloc_sized_lrecord_1):
+	* alloc.c (alloc_sized_lrecord_array):
+	* alloc.c (alloc_lrecord_array):
+	* alloc.c (copy_lisp_object):
+	* alloc.c (dbg_inhibit_dbg_symbol_deletion):
+	* alloc.c (make_uninit_vector):
+	* alloc.c (Fvector):
+	* alloc.c (bit_vector_equal):
+	* alloc.c (make_bit_vector):
+	* alloc.c (string_equal):
+	* alloc.c (resize_string):
+	* alloc.c (set_string_char):
+	* alloc.c (Fmake_string):
+	* alloc.c (Fstring):
+	* alloc.c (init_string_ascii_begin):
+	* alloc.c (make_string):
+	* alloc.c (dec_lrecord_stats):
+	* alloc.c (lrecord_stats_heap_size):
+	* alloc.c (pluralize_word):
+	* array.c (Dynarr_realloc):
+	* array.c (Dynarr_insert_many):
+	* array.c (Dynarr_delete_many):
+	* array.c (gap_array_move_gap):
+	* array.h:
+	* array.h (Dynarr_declare):
+	* array.h (Dynarr_delete_object):
+	* array.h (gap_array_marker):
+	* buffer.c (MARKED_SLOT):
+	* buffer.c (Fgenerate_new_buffer_name):
+	* buffer.c (DEFVAR_BUFFER_LOCAL_1):
+	* buffer.h (struct buffer):
+	* bytecode.c (make_compiled_function_args):
+	* bytecode.c (UNUSED):
+	* callint.c (Fcall_interactively):
+	* casefiddle.c (casify_object):
+	* casefiddle.c (casify_region_internal):
+	* charset.h:
+	* chartab.c (clone_chartab_table):
+	* chartab.c (put_char_table):
+	* chartab.c (decode_char_table_range):
+	* cmds.c (Fpoint_at_bol):
+	* cmds.c (Fpoint_at_eol):
+	* cmds.c (internal_self_insert):
+	* console.c (delete_console_internal):
+	* console.c (Fset_input_mode):
+	* console.c (DEFVAR_CONSOLE_LOCAL_1):
+	* console.h:
+	* data.c (lisp_to_uint32_t):
+	* data.c (lisp_to_int32_t):
+	* data.c (rem_two_fixnum):
+	* data.c (Flsh):
+	* debug.c (FROB):
+	* device.c (Fmake_device):
+	* device.c (delete_device_internal):
+	* device.c (Fset_device_baud_rate):
+	* device.h:
+	* doc.c (extract_object_file_name):
+	* doc.c (Fsnarf_documentation):
+	* doc.c (verify_doc_mapper):
+	* doc.c (Fsubstitute_command_keys):
+	* doprnt.c (Fnumber_to_string):
+	* doprnt.c (emacs_doprnt):
+	* editfns.c (Finsert_char):
+	* editfns.c (save_restriction_restore):
+	* elhash.c (internal_array_hash):
+	* filelock.c (LOCK_PID_MAX):
+	* filelock.c (fill_in_lock_file_name):
+	* filelock.c (current_lock_owner):
+	* indent.c:
+	* indent.c (column_at_point):
+	* indent.c (string_column_at_point):
+	* indent.c (current_column):
+	* indent.c (Findent_to):
+	* indent.c (byte_spaces_at_point):
+	* indent.c (Fmove_to_column):
+	* indent.c (Fcompute_motion):
+	* indent.c (vertical_motion_1):
+	* indent.c (Fvertical_motion_pixels):
+	* lisp-disunion.h (XCHARVAL):
+	* lisp-disunion.h (wrap_pointer_1):
+	* lisp.h:
+	* lisp.h (ALLOCA):
+	* lisp.h (XSET_STRING_ASCII_BEGIN):
+	* lisp.h (CHECK_CHAR_COERCE_INT):
+	* lisp.h (LISP_HASH):
+	* lisp.h (struct gcpro):
+	* lisp.h (DECLARE_INLINE_HEADER):
+	* lrecord.h:
+	* lrecord.h (set_lheader_implementation):
+	* number.h:
+	* number.h (integer_signum):
+	* number.h (NATNUMP):
+	* print.c (debug_short_backtrace):
+	* search.c (find_before_next_newline):
+	* syntax.c (scan_words):
+	* syntax.h:
+	* sysdep.c:
+	* sysdep.c (wait_for_termination):
+	* sysdep.c (sys_subshell):
+	* sysdep.c (sys_suspend):
+	* sysdep.c (init_sigio_on_device):
+	* sysdep.c (qxe_readlink):
+	* sysfile.h:
+	* text.c (eifind_large_enough_buffer):
+	* text.h:
+	* text.h (ASSERT_ASCTEXT_ASCII_LEN):
+	* text.h (struct):
+	* text.h (EI_ALLOC):
+	* text.h (eicpy_lstr_off):
+	* text.h (eicpy_raw_fmt):
+	* text.h (eicpy_ascii_len):
+	* text.h (eicpy_ext_len):
+	* text.h (eimake_string_off):
+	* text.h (DECLARE_INLINE_HEADER):
+	* text.h (eicat_1):
+	* text.h (eicat_ascii):
+	* text.h (eicat_raw):
+	* text.h (eisub_1):
+	* text.h (eisub_ascii):
+	* text.h (EI_CASECHANGE):
+	* undo.c (truncate_undo_list):
+	* unicode.c (print_precedence_array):
+	Be more careful about integer types within the C code, e.g. not
+	using an int where a value represents a (possibly large) number of
+	bytes, or characters, especially relevant for values like fill
+	columns, which can usefully be set to most-positive-fixnum,
+	something the code up to now dealt with badly on a 64-bit build.
+	Issues flushed out using the -Wnarrowing GCC option.
+
+	* lisp.h (XCHAR_OR_CHAR_INT):
+	Provide an error-checking version of this to check uses with
+	fixnums where valid_ichar_p() is not true.
+
+	* lisp.h (GOOD_HASH):
+	Set this to a prime number just over 2^32 on sixty-four bit
+	architectures, of type Hashcode, an unsigned type, so modular
+	arithmetic is defined.
+
 2018-04-21  Aidan Kehoe  <kehoea(a)parhasard.net>
 
 	* data.c:
diff -r 046a3f85a39d -r c5889f9bb7f4 src/abbrev.c
--- a/src/abbrev.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/abbrev.c	Mon Apr 23 13:43:40 2018 +0100
@@ -284,7 +284,7 @@
 {
   /* This function can GC */
   struct buffer *buf = current_buffer;
-  int oldmodiff = BUF_MODIFF (buf);
+  EMACS_INT oldmodiff = BUF_MODIFF (buf);
   Lisp_Object pre_modiff_p;
   Charbpos point;			/* position of point */
   Charbpos abbrev_start;		/* position of abbreviation beginning */
diff -r 046a3f85a39d -r c5889f9bb7f4 src/alloc.c
--- a/src/alloc.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/alloc.c	Mon Apr 23 13:43:40 2018 +0100
@@ -150,9 +150,9 @@
 
 static struct
 {
-  int instances_in_use;
-  int bytes_in_use;
-  int bytes_in_use_including_overhead;
+  Elemcount instances_in_use;
+  Bytecount bytes_in_use;
+  Bytecount bytes_in_use_including_overhead;
 } lrecord_stats [countof (lrecord_implementations_table)];
 
 #else /* not NEW_GC */
@@ -315,7 +315,7 @@
 static void
 malloc_after (void *val, Bytecount size)
 {
-  if (!val && size != 0)
+  if (size < 0 || (!val && size != 0))
     memory_full ();
   set_alloc_mins_and_maxes (val, size);
 }
@@ -393,7 +393,7 @@
 {
   void *val;
   MALLOC_BEGIN ();
-  val = malloc (size);
+  val = malloc ((size_t) size);
   MALLOC_END ();
   malloc_after (val, size);
   return val;
@@ -405,7 +405,7 @@
 {
   void *val;
   MALLOC_BEGIN ();
-  val= calloc (nelem, elsize);
+  val= calloc ((size_t) nelem, (size_t) elsize);
   MALLOC_END ();
   malloc_after (val, nelem * elsize);
   return val;
@@ -422,7 +422,7 @@
 xrealloc (void *block, Bytecount size)
 {
   FREE_OR_REALLOC_BEGIN (block);
-  block = realloc (block, size);
+  block = realloc (block, (size_t) size);
   MALLOC_END ();
   malloc_after (block, size);
   return block;
@@ -454,8 +454,10 @@
 char *
 xstrdup (const char *str)
 {
-  int len = strlen (str) + 1;   /* for stupid terminating 0 */
-  void *val = xmalloc (len);
+  size_t len = strlen (str) + 1;   /* for stupid terminating 0 */
+  void *val;
+
+  val = xmalloc ((Bytecount) len);
 
   if (val == 0) return 0;
   return (char *) memcpy (val, str, len);
@@ -596,7 +598,7 @@
 
   assert_proper_sizing (size);
 
-  lheader = (struct lrecord_header *) mc_alloc (size);
+  lheader = (struct lrecord_header *) mc_alloc ((size_t) size);
   gc_checking_assert (LRECORD_FREE_P (lheader));
   set_lheader_implementation (lheader, implementation);
 #ifdef ALLOC_TYPE_STATS
@@ -641,7 +643,7 @@
 }
 
 Lisp_Object
-alloc_sized_lrecord_array (Bytecount size, int elemcount,
+alloc_sized_lrecord_array (Bytecount size, Elemcount elemcount,
 			   const struct lrecord_implementation *implementation)
 {
   struct lrecord_header *lheader;
@@ -671,7 +673,7 @@
 }
 
 Lisp_Object
-alloc_lrecord_array (int elemcount,
+alloc_lrecord_array (Elemcount elemcount,
 		     const struct lrecord_implementation *implementation)
 {
   type_checking_assert (implementation->static_size > 0);
@@ -767,7 +769,7 @@
 #ifdef NEW_GC
   memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lrecord_header),
 	  (char *) XRECORD_LHEADER (src) + sizeof (struct lrecord_header),
-	  size - sizeof (struct lrecord_header));
+	  size - (Bytecount) sizeof (struct lrecord_header));
 #else /* not NEW_GC */
   if (imp->frob_block_p)
     memcpy ((char *) XRECORD_LHEADER (dst) + sizeof (struct lrecord_header),
@@ -896,8 +898,8 @@
 
 /* On some systems, the above definitions will be optimized away by
    the compiler or linker unless they are referenced in some function. */
-long dbg_inhibit_dbg_symbol_deletion (void);
-long
+EMACS_UINT dbg_inhibit_dbg_symbol_deletion (void);
+EMACS_UINT
 dbg_inhibit_dbg_symbol_deletion (void)
 {
   return
@@ -1857,7 +1859,7 @@
 make_uninit_vector (Elemcount sizei)
 {
   /* no `next' field; we use lcrecords */
-  EMACS_UINT sizeui = sizei;
+  EMACS_UINT sizeui = (EMACS_UINT) sizei;
   EMACS_UINT sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object,
                                                    contents, sizeui);
   Lisp_Object obj;
@@ -1910,7 +1912,7 @@
                           check_integer_range() does <=, adjust for this. */
                        make_fixnum (ARRAY_DIMENSION_LIMIT - 1));
   result = make_uninit_vector (nargs);
-  memcpy (XVECTOR_DATA (result), args, sizeof (Lisp_Object) * nargs);
+  memcpy (XVECTOR_DATA (result), args, sizeof (Lisp_Object) * (size_t) nargs);
   return result;
 }
 
@@ -2057,8 +2059,8 @@
 
   return ((bit_vector_length (v1) == bit_vector_length (v2)) &&
 	  !memcmp (v1->bits, v2->bits,
-		   BIT_VECTOR_LONG_STORAGE (bit_vector_length (v1)) *
-		   sizeof (long)));
+		   (size_t) BIT_VECTOR_LONG_STORAGE (bit_vector_length (v1))
+		   * sizeof (long)));
 }
 
 /* This needs to be algorithmically identical to internal_array_hash in
@@ -2156,15 +2158,18 @@
 {
   Lisp_Bit_Vector *p = make_bit_vector_internal (length);
   Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (length);
+  size_t bcount = (size_t) num_longs * sizeof (long);
 
   CHECK_BIT (bit);
 
+  structure_checking_assert ((bcount / (size_t) num_longs) == sizeof (long));
+
   if (ZEROP (bit))
-    memset (p->bits, 0, num_longs * sizeof (long));
+    memset (p->bits, 0, bcount);
   else
     {
       Elemcount bits_in_last = length & (LONGBITS_POWER_OF_2 - 1);
-      memset (p->bits, ~0, num_longs * sizeof (long));
+      memset (p->bits, ~0, bcount);
       /* But we have to make sure that the unused bits in the
 	 last long are 0, so that equal/hash is easy. */
       if (bits_in_last)
@@ -2672,7 +2677,8 @@
     return !lisp_strcasecmp_i18n (obj1, obj2);
   else
     return (((len = XSTRING_LENGTH (obj1)) == XSTRING_LENGTH (obj2)) &&
-	    !memcmp (XSTRING_DATA (obj1), XSTRING_DATA (obj2), len));
+	    !memcmp (XSTRING_DATA (obj1), XSTRING_DATA (obj2),
+		     (size_t) len));
 }
 
 static const struct memory_description string_description[] = {
@@ -3056,14 +3062,16 @@
   
   if (delta < 0 && pos >= 0)
     memmove (XSTRING_DATA (s) + pos + delta,
-	     XSTRING_DATA (s) + pos, len);
+	     /* LEN is guaranteed greater than zero. */
+	     XSTRING_DATA (s) + pos, (size_t) len);
   
   XSTRING_DATA_OBJECT (s) = 
     wrap_string_direct_data (mc_realloc (XPNTR (XSTRING_DATA_OBJECT (s)),
 					 newfullsize));
   if (delta > 0 && pos >= 0)
     memmove (XSTRING_DATA (s) + pos + delta, XSTRING_DATA (s) + pos,
-	     len);
+	     /* LEN is guaranteed greater than zero. */
+	     (size_t) len);
   
 #else /* not NEW_GC */
   oldfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s));
@@ -3222,10 +3230,10 @@
   /* XSTRING_DATA (ss) might have changed, reload it. */
   data = XSTRING_DATA (ss) + bytoff;
 
-  memcpy (data, newstr, newlen);
+  memcpy (data, newstr, (size_t) newlen);
   if (oldlen != newlen) 
     {
-      if (newlen > 1 && idx <= (Charcount) XSTRING_ASCII_BEGIN (ss))
+      if (newlen > 1 && idx < (Charcount) XSTRING_ASCII_BEGIN (ss))
       /* Everything starting with the new char is no longer part of
 	 ascii_begin */
 	XSET_STRING_ASCII_BEGIN (ss, idx);
@@ -3238,9 +3246,7 @@
 	      if (!byte_ascii_p (XSTRING_DATA (ss)[jj]))
 		break;
 	    }
-	  XSET_STRING_ASCII_BEGIN (ss,
-                                   min (jj,
-                                        (Bytecount) MAX_STRING_ASCII_BEGIN));
+	  XSET_STRING_ASCII_BEGIN (ss, jj);
 	}
     }
   sledgehammer_check_ascii_begin (ss);
@@ -3269,9 +3275,9 @@
                            make_fixnum (STRING_BYTE_TOTAL_SIZE_LIMIT - 1));
 
       val = make_uninit_string (XFIXNUM (length));
-      memset (XSTRING_DATA (val), XCHAR (character), XSTRING_LENGTH (val));
-      XSET_STRING_ASCII_BEGIN (val, min (MAX_STRING_ASCII_BEGIN,
-                                         XSTRING_LENGTH (val)));
+      memset (XSTRING_DATA (val), XCHAR (character),
+	      (size_t) XSTRING_LENGTH (val));
+      XSET_STRING_ASCII_BEGIN (val, XSTRING_LENGTH (val));
     }
   else if (FIXNUMP (length) && XREALFIXNUM (length) >= 0)
     {
@@ -3304,7 +3310,7 @@
       val = make_uninit_string ((Bytecount) product);
       ptr = XSTRING_DATA (val);
 
-      for (i = clen; i; i--)
+      for (i = (EMACS_INT) clen; i; i--)
         {
           Ibyte *init_ptr = init_str;
           switch (onelen)
@@ -3350,7 +3356,7 @@
                        make_fixnum ((STRING_BYTE_TOTAL_SIZE_LIMIT - 1) /
                                     MAX_ICHAR_LEN));
 
-  storage = p = alloca_ibytes (nargs * MAX_ICHAR_LEN);
+  storage = p = alloca_ibytes ((size_t) nargs * MAX_ICHAR_LEN);
 
   for (; nargs; nargs--, args++)
     {
@@ -3400,10 +3406,9 @@
       if (!byte_ascii_p (contents[i]))
 	break;
     }
-  XSET_STRING_ASCII_BEGIN (string, min (i, MAX_STRING_ASCII_BEGIN));
+  XSET_STRING_ASCII_BEGIN (string, i);
 #else
-  XSET_STRING_ASCII_BEGIN (string, min (XSTRING_LENGTH (string),
-					MAX_STRING_ASCII_BEGIN));
+  XSET_STRING_ASCII_BEGIN (string, XSTRING_LENGTH (string));
 #endif
   sledgehammer_check_ascii_begin (string);
 }
@@ -3421,7 +3426,7 @@
 #endif
 
   val = make_uninit_string (length);
-  memcpy (XSTRING_DATA (val), contents, length);
+  memcpy (XSTRING_DATA (val), contents, (size_t) length);
   init_string_ascii_begin (val);
   sledgehammer_check_ascii_begin (val);  
   return val;
@@ -4196,7 +4201,7 @@
 		   const struct lrecord_header *h)
 {
   int type_index = h->type;
-  int size = detagged_lisp_object_size (h);
+  Bytecount size = detagged_lisp_object_size (h);
 
   lrecord_stats[type_index].instances_in_use--;
   lrecord_stats[type_index].bytes_in_use -= size;
@@ -4206,11 +4211,11 @@
   DECREMENT_CONS_COUNTER (size);
 }
 
-int
+Bytecount
 lrecord_stats_heap_size (void)
 {
   int i;
-  int size = 0;
+  Bytecount size = 0;
   for (i = 0; i < countof (lrecord_implementations_table); i++)
     size += lrecord_stats[i].bytes_in_use;
   return size;
@@ -4395,7 +4400,7 @@
 static void
 pluralize_word (Ascbyte *buf)
 {
-  Bytecount len = strlen (buf);
+  size_t len = strlen (buf);
   int upper = 0;
   Ascbyte d, e;
 
diff -r 046a3f85a39d -r c5889f9bb7f4 src/array.c
--- a/src/array.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/array.c	Mon Apr 23 13:43:40 2018 +0100
@@ -308,16 +308,27 @@
 static void
 Dynarr_realloc (Dynarr *dy, Elemcount new_size)
 {
+  size_t bcount = (size_t) new_size * (size_t) (Dynarr_elsize (dy));
+
+  if ((bcount / (size_t) new_size) != (size_t) Dynarr_elsize (dy))
+    {
+      memory_full ();
+    }
+
   if (DUMPEDP (dy->base))
     {
-      void *new_base = malloc (new_size * Dynarr_elsize (dy));
-      memcpy (new_base, dy->base, 
-	      (Dynarr_max (dy) < new_size ? Dynarr_max (dy) : new_size) *
-	      Dynarr_elsize (dy));
+      size_t copycount
+	= (size_t) (Dynarr_max (dy) < new_size ? Dynarr_max (dy) : new_size) 
+	* (size_t) Dynarr_elsize (dy);
+      void *new_base = malloc (bcount);
+      memcpy (new_base, dy->base, copycount);
       dy->base = new_base;
     }
   else
-    dy->base = xrealloc (dy->base, new_size * Dynarr_elsize (dy));
+    {
+      malloc_checking_assert ((Bytecount) bcount >= 0);
+      dy->base = xrealloc (dy->base, bcount);
+    }
 }
 
 void *
@@ -407,28 +418,40 @@
 
   if (pos != old_len)
     {
+      size_t bcount = (size_t) (old_len - pos) * (size_t) Dynarr_elsize (dy);
+      if ((bcount / (size_t) ((old_len - pos)))	\
+	  != (size_t) Dynarr_elsize (dy))
+	{
+	  /* Overflow */
+	  memory_full ();
+	}
       memmove ((Rawbyte *) dy->base + (pos + len)*Dynarr_elsize (dy),
-	       (Rawbyte *) dy->base + pos*Dynarr_elsize (dy),
-	       (old_len - pos)*Dynarr_elsize (dy));
+	       (Rawbyte *) dy->base + pos*Dynarr_elsize (dy), bcount);
     }
   /* Some functions call us with a value of 0 to mean "reserve space but
      don't write into it" */
   if (base)
-    memcpy ((Rawbyte *) dy->base + pos*Dynarr_elsize (dy), base,
-	    len*Dynarr_elsize (dy));
+    {
+      size_t bcount = (size_t) len * (size_t) (Dynarr_elsize (dy));
+      dynarr_checking_assert ((Bytecount) bcount >= 0);
+      memcpy ((Rawbyte *) dy->base + pos*Dynarr_elsize (dy), base, bcount);
+    }
 }
 
 void
 Dynarr_delete_many (void *d, Elemcount pos, Elemcount len)
 {
   Dynarr *dy = Dynarr_verify_mod (d);
+  size_t bcount
+    = (size_t) (Dynarr_length (dy) - pos - len) * (size_t) Dynarr_elsize (dy);
 
   dynarr_checking_assert (pos >= 0 && len >= 0 &&
 			  pos + len <= Dynarr_length (dy));
+  /* Not checking on overflow for BCOUNT because we're reducing the size
+     used, we had to have overflowed already. */
 
   memmove ((Rawbyte *) dy->base + pos*Dynarr_elsize (dy),
-	   (Rawbyte *) dy->base + (pos + len)*Dynarr_elsize (dy),
-	   (Dynarr_length (dy) - pos - len)*Dynarr_elsize (dy));
+	   (Rawbyte *) dy->base + (pos + len)*Dynarr_elsize (dy), bcount);
 
   Dynarr_set_length_1 (dy, Dynarr_length (dy) - len);
 }
@@ -771,17 +794,21 @@
 
   if (pos < gap)
     {
+      size_t bcount = (size_t) (gap - pos) * (size_t) (ga->elsize);
+      structure_checking_assert ((bcount / (size_t) (gap - pos))
+				 == (size_t) (ga->elsize));
       memmove (GAP_ARRAY_MEMEL_ADDR (ga, pos + gapsize),
-	       GAP_ARRAY_MEMEL_ADDR (ga, pos),
-	       (gap - pos)*ga->elsize);
+	       GAP_ARRAY_MEMEL_ADDR (ga, pos), bcount);
       gap_array_adjust_markers (ga, (Memxpos) pos, (Memxpos) gap,
 				gapsize);
     }
   else if (pos > gap)
     {
+      size_t bcount = (size_t) (pos - gap) * (size_t) (ga->elsize);
+      structure_checking_assert ((bcount / (size_t) (pos - gap))
+				 == (size_t) (ga->elsize));
       memmove (GAP_ARRAY_MEMEL_ADDR (ga, gap),
-	       GAP_ARRAY_MEMEL_ADDR (ga, gap + gapsize),
-	       (pos - gap)*ga->elsize);
+	       GAP_ARRAY_MEMEL_ADDR (ga, gap + gapsize), bcount);
       gap_array_adjust_markers (ga, (Memxpos) (gap + gapsize),
 				(Memxpos) (pos + gapsize), - gapsize);
     }
diff -r 046a3f85a39d -r c5889f9bb7f4 src/array.h
--- a/src/array.h	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/array.h	Mon Apr 23 13:43:40 2018 +0100
@@ -51,10 +51,10 @@
   type *base;					\
   DECLARE_DYNARR_LISP_IMP ()			\
   DECLARE_DYNARR_LOCKED ()			\
-  int elsize_;					\
-  int len_;					\
-  int largest_;					\
-  int max_
+  Bytecount elsize_;				\
+  Elemcount len_;				\
+  Elemcount largest_;				\
+  Elemcount max_
 
 typedef struct dynarr
 {
@@ -152,7 +152,7 @@
 
 #ifdef ERROR_CHECK_DYNARR
 DECLARE_INLINE_HEADER (
-int
+Elemcount
 Dynarr_verify_pos_at (void *d, Elemcount pos, const Ascbyte *file, int line)
 )
 {
@@ -164,7 +164,7 @@
 }
 
 DECLARE_INLINE_HEADER (
-int
+Elemcount
 Dynarr_verify_pos_atp (void *d, Elemcount pos, const Ascbyte *file, int line)
 )
 {
@@ -204,7 +204,7 @@
 }
 
 DECLARE_INLINE_HEADER (
-int
+Elemcount
 Dynarr_verify_pos_atp_allow_end (void *d, Elemcount pos, const Ascbyte *file,
 				 int line)
 )
@@ -441,8 +441,9 @@
 )
 {
   Dynarr *dy = Dynarr_verify_mod (d);
-  memset ((Rawbyte *) dy->base + pos*Dynarr_elsize (dy), 0,
-	  len*Dynarr_elsize (dy));
+  size_t bcount = (size_t) len * (size_t) (Dynarr_elsize (dy));
+
+  memset ((Rawbyte *) dy->base + pos*Dynarr_elsize (dy), 0, bcount);
 }
 
 /* This is an optimization.  This is like Dynarr_set_length_and_zero() but
@@ -543,8 +544,10 @@
   Elemcount pos = Dynarr_length (dy);
   Dynarr_increase_length (dy, Dynarr_length (dy) + len);
   if (base)
-    memcpy ((Rawbyte *) dy->base + pos*Dynarr_elsize (dy), base,
-	    len*Dynarr_elsize (dy));
+    {
+      size_t bcount = (size_t) len * (size_t) Dynarr_elsize (dy);
+      memcpy ((Rawbyte *) dy->base + pos*Dynarr_elsize (dy), base, bcount);
+    }
 }
 
 /* Insert LEN elements, currently pointed to by BASE, into dynarr D
@@ -606,7 +609,7 @@
 #define Dynarr_delete_object(d, el)				\
 do								\
 {								\
-  REGISTER int _ddo_i;						\
+  REGISTER Elemcount _ddo_i;					\
   for (_ddo_i = Dynarr_length (d) - 1; _ddo_i >= 0; _ddo_i--)	\
     {								\
       if (el == Dynarr_at (d, _ddo_i))				\
@@ -767,7 +770,7 @@
 #ifdef NEW_GC
   NORMAL_LISP_OBJECT_HEADER header;
 #endif /* NEW_GC */
-  int pos;
+  Elemcount pos;
   struct gap_array_marker *next;
 } Gap_Array_Marker;
 
diff -r 046a3f85a39d -r c5889f9bb7f4 src/buffer.c
--- a/src/buffer.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/buffer.c	Mon Apr 23 13:43:40 2018 +0100
@@ -749,7 +749,7 @@
   /* For each slot that has a default value,
      copy that into the slot.  */
 #define MARKED_SLOT(slot)						\
-  { int mask = XFIXNUM (buffer_local_flags.slot);				\
+  { EMACS_INT mask = XFIXNUM (buffer_local_flags.slot);			\
     if ((mask > 0 || mask == -1 || mask == -3)				\
 	&& (first_time							\
 	    || NILP (Fget (XBUFFER (Vbuffer_local_symbols)->slot,	\
@@ -811,7 +811,7 @@
     }
 
   csize = XSTRING_LENGTH (name) + DECIMAL_PRINT_SIZE (EMACS_INT)
-    + sizeof ("<>");
+    + (Bytecount) (sizeof ("<>"));
   candidate = alloca_ibytes (csize);
 
   count = itext_ichar_eql (XSTRING_DATA (name), ' ') ? get_random () : 1;
@@ -954,7 +954,7 @@
   {
     struct buffer *syms = XBUFFER (Vbuffer_local_symbols);
 #define MARKED_SLOT(slot)					\
-    { int mask = XFIXNUM (buffer_local_flags.slot);		\
+    { EMACS_INT mask = XFIXNUM (buffer_local_flags.slot);	\
       if (mask == 0 || mask == -1				\
 	  || ((mask > 0) && (buf->local_var_flags & mask)))	\
         result = Fcons (Fcons (syms->slot, buf->slot), result);	\
@@ -2221,8 +2221,8 @@
   MARK_LRECORD_AS_LISP_READONLY (I_hate_C);				  \
 									  \
   {									  \
-    int offset = ((char *)symbol_value_forward_forward (I_hate_C) -	  \
-		  (char *)&buffer_local_flags);				  \
+    ssize_t offset = ((char *)symbol_value_forward_forward (I_hate_C) -	  \
+		      (char *)&buffer_local_flags);			  \
     defvar_magic (lname, I_hate_C);					  \
 									  \
     *((Lisp_Object *)(offset + (char *)XBUFFER (Vbuffer_local_symbols)))  \
diff -r 046a3f85a39d -r c5889f9bb7f4 src/buffer.h
--- a/src/buffer.h	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/buffer.h	Mon Apr 23 13:43:40 2018 +0100
@@ -239,7 +239,7 @@
 
   /* Flags saying which DEFVAR_PER_BUFFER variables
      are local to this buffer.  */
-  int local_var_flags;
+  EMACS_INT local_var_flags;
 
   /* Set to the modtime of the visited file when read or written.
      -1 means visited file was nonexistent.
diff -r 046a3f85a39d -r c5889f9bb7f4 src/bytecode.c
--- a/src/bytecode.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/bytecode.c	Mon Apr 23 13:43:40 2018 +0100
@@ -60,14 +60,16 @@
 
 #ifdef NEW_GC
 static Lisp_Object
-make_compiled_function_args (int totalargs)
+make_compiled_function_args (Elemcount totalargs)
 {
+  size_t bcount
+    = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Compiled_Function_Args, 
+				    Lisp_Object, args, (size_t) totalargs);
   Lisp_Compiled_Function_Args *args;
+  structure_checking_assert ((Bytecount) bcount >= 0);
+
   args = XCOMPILED_FUNCTION_ARGS
-    (ALLOC_SIZED_LISP_OBJECT 
-     (FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Compiled_Function_Args, 
-				    Lisp_Object, args, totalargs),
-      compiled_function_args));
+    (ALLOC_SIZED_LISP_OBJECT ((Bytecount) bcount, compiled_function_args));
   args->size = totalargs;
   return wrap_compiled_function_args (args);
 }
@@ -1470,7 +1472,7 @@
 		     const Opbyte *UNUSED (program_ptr),
 		     Opcode opcode)
 {
-  REGISTER int n;
+  REGISTER EMACS_INT n;
 
   switch (opcode)
     {
diff -r 046a3f85a39d -r c5889f9bb7f4 src/callint.c
--- a/src/callint.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/callint.c	Mon Apr 23 13:43:40 2018 +0100
@@ -281,10 +281,10 @@
 #endif
   /* If SPECS is a string, we reset prompt_data to XSTRING_DATA (specs)
      every time a GC might have occurred */
-  const char *prompt_data = 0;
-  int prompt_index = 0;
+  const Ibyte *prompt_data = 0;
+  Bytecount prompt_index = 0;
   int argcount;
-  int set_zmacs_region_stays = 0;
+  Boolint set_zmacs_region_stays = 0;
   int mouse_event_count = 0;
 
   if (!NILP (keys))
@@ -316,7 +316,7 @@
 
   if (SUBRP (fun))
     {
-      prompt_data = XSUBR (fun)->prompt;
+      prompt_data = (const Ibyte *) XSUBR (fun)->prompt;
       if (!prompt_data)
 	{
 	lose:
@@ -369,7 +369,7 @@
   if (!STRINGP (specs) && prompt_data == 0)
     {
       struct gcpro gcpro1, gcpro2, gcpro3;
-      int i = num_input_chars;
+      Charcount i = num_input_chars;
       Lisp_Object input = specs;
 
       GCPRO3 (function, specs, input);
@@ -466,7 +466,7 @@
     for (;;)
       {
 	if (STRINGP (specs))
-	  prompt_data = (const char *) XSTRING_DATA (specs);
+	  prompt_data = (const Ibyte *) XSTRING_DATA (specs);
 
 	if (prompt_data[prompt_index] == '+')
 	  syntax_error ("`+' is not used in `interactive' for ordinary commands", Qunbound);
@@ -527,7 +527,7 @@
      us give to the function.  */
   argcount = 0;
   {
-    const char *tem;
+    const Ibyte *tem;
     for (tem = prompt_data + prompt_index; *tem; )
       {
 	/* 'r' specifications ("point and mark as 2 numeric args")
@@ -536,7 +536,7 @@
 	  argcount += 2;
 	else
 	  argcount += 1;
-	tem = (const char *) strchr (tem + 1, '\n');
+	tem = qxestrchr (tem + 1, '\n');
 	if (!tem)
 	  break;
 	tem++;
@@ -575,11 +575,11 @@
   {
     /* args[-1] is the function to call */
     /* args[n] is the n'th argument to the function */
-    int alloca_size = (1	/* function to call */
-                       + argcount /* actual arguments */
-                       + argcount /* visargs */
-                       + argcount /* varies */
-                       );
+    Bytecount alloca_size = (1	/* function to call */
+			     + argcount /* actual arguments */
+			     + argcount /* visargs */
+			     + argcount /* varies */
+			     );
     Lisp_Object *args = alloca_array (Lisp_Object, alloca_size) + 1;
     /* visargs is an array of either Qnil or user-friendlier versions (often
      *  strings) of previous arguments, to use in prompts for successive
@@ -590,7 +590,7 @@
        its value in this call quoted in the command history.  It should be
        recorded as a call to the function named varies[i]]. */
     Lisp_Object *varies = visargs + argcount;
-    int arg_from_tty = 0;
+    Boolint arg_from_tty = 0;
     REGISTER int argnum;
     struct gcpro gcpro1, gcpro2;
 
@@ -606,12 +606,12 @@
 
     for (argnum = 0; ; argnum++)
       {
-	const char *prompt_start = prompt_data + prompt_index + 1;
-	const char *prompt_limit = (const char *) strchr (prompt_start, '\n');
-	int prompt_length;
+	const Ibyte *prompt_start = prompt_data + prompt_index + 1;
+	const Ibyte *prompt_limit = qxestrchr (prompt_start, '\n');
+	Bytecount prompt_length;
 	prompt_length = ((prompt_limit)
 			 ? (prompt_limit - prompt_start)
-			 : (int) strlen (prompt_start));
+			 : qxestrlen (prompt_start));
 	if (prompt_limit && prompt_limit[1] == 0)
 	  {
 	    prompt_limit = 0;	/* "sfoo:\n" -- strip tailing return */
@@ -933,7 +933,7 @@
 	if (!prompt_limit)
 	  break;
 	if (STRINGP (specs))
-	  prompt_data = (const char *) XSTRING_DATA (specs);
+	  prompt_data = (const Ibyte *) XSTRING_DATA (specs);
 	prompt_index += prompt_length + 1 + 1; /* +1 to skip spec, +1 for \n */
       }
     unbind_to (speccount);
diff -r 046a3f85a39d -r c5889f9bb7f4 src/casefiddle.c
--- a/src/casefiddle.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/casefiddle.c	Mon Apr 23 13:43:40 2018 +0100
@@ -68,7 +68,7 @@
       Ibyte *newp = storage;
       Ibyte *oldp = XSTRING_DATA (string_or_char);
       Ibyte *endp = oldp + XSTRING_LENGTH (string_or_char);
-      int wordp = 0, wordp_prev;
+      Boolint wordp = 0, wordp_prev;
 
       while (oldp < endp)
 	{
@@ -203,7 +203,7 @@
   Charbpos pos, s, e;
   Lisp_Object syntax_table = BUFFER_MIRROR_SYNTAX_TABLE (buf);
   int mccount;
-  int wordp = 0, wordp_prev;
+  Boolint wordp = 0, wordp_prev;
 
   if (EQ (start, end))
     /* Not modifying because nothing marked */
diff -r 046a3f85a39d -r c5889f9bb7f4 src/charset.h
--- a/src/charset.h	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/charset.h	Mon Apr 23 13:43:40 2018 +0100
@@ -989,7 +989,7 @@
    to the Dynarr.  FAIL controls failure mode when charset conversion to
    Unicode is not possible. */
 DECLARE_INLINE_HEADER (
-int
+Bytecount
 charset_codepoint_to_dynarr (Lisp_Object charset, int c1, int c2,
 			     unsigned_char_dynarr *dst,
 			     enum converr USED_IF_MULE (fail))
diff -r 046a3f85a39d -r c5889f9bb7f4 src/chartab.c
--- a/src/chartab.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/chartab.c	Mon Apr 23 13:43:40 2018 +0100
@@ -269,7 +269,6 @@
 clone_chartab_table (Lisp_Object table, int level, int catp)
 {
   Lisp_Object newtab;
-  Bytecount size;
 
   check_chartab_invariants (table, level, catp);
 
@@ -280,10 +279,9 @@
       return table;
     }
 
-  size = sizeof (Lisp_Object);
   newtab = ALLOCATE_LEVEL_N_SUBTAB ();
   memcpy (SUBTAB_ARRAY_FROM_SUBTAB (newtab), SUBTAB_ARRAY_FROM_SUBTAB (table),
-	  256 * size);
+	  256 * sizeof (Lisp_Object));
 
   {
     int i;
@@ -506,7 +504,7 @@
   int levels;
 #ifndef MAXIMIZE_CHAR_TABLE_DEPTH
   int code_levels;
-  int catp = XCHAR_TABLE_CATEGORY_P (chartab);
+  Boolint catp = XCHAR_TABLE_CATEGORY_P (chartab);
 #endif
 
   /* DO NOT check to see whether START and END are valid Ichars.  They
@@ -1217,8 +1215,6 @@
 			     range);
       outrange->type = CHARTAB_RANGE_ROW;
       outrange->charset = Fget_charset (elts[0]);
-      CHECK_FIXNUM (elts[1]);
-      outrange->row = XFIXNUM (elts[1]);
       if (XCHARSET_DIMENSION (outrange->charset) == 1)
 	sferror ("Charset in row vector must be multi-byte",
 		 outrange->charset);
@@ -1229,6 +1225,7 @@
              make_fixnum (XCHARSET_OFFSET (outrange->charset, 0) +
                        XCHARSET_CHARS (outrange->charset, 0) - 1));
 	}
+      outrange->row = (int) XFIXNUM (elts[1]);
     }
   else
     {
diff -r 046a3f85a39d -r c5889f9bb7f4 src/cmds.c
--- a/src/cmds.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/cmds.c	Mon Apr 23 13:43:40 2018 +0100
@@ -170,7 +170,7 @@
        (count, buffer))
 {
   struct buffer *b = decode_buffer (buffer, 1);
-  REGISTER int orig, end;
+  REGISTER Charbpos orig, end;
 
   buffer = wrap_buffer (b);
   if (NILP (count))
@@ -228,7 +228,7 @@
     }
 
   return make_fixnum (find_before_next_newline (buf, BUF_PT (buf), 0,
-					     n - (n <= 0)));
+						n - (n <= 0)));
 }
 
 DEFUN ("end-of-line", Fend_of_line, 0, 2, "_p", /*
@@ -379,7 +379,7 @@
   Lisp_Object overwrite;
   Lisp_Object syntax_table;
   struct buffer *buf = current_buffer;
-  int tab_width;
+  Charcount tab_width;
 
   overwrite = buf->overwrite_mode;
   syntax_table = BUFFER_MIRROR_SYNTAX_TABLE (buf);
diff -r 046a3f85a39d -r c5889f9bb7f4 src/console.c
--- a/src/console.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/console.c	Mon Apr 23 13:43:40 2018 +0100
@@ -681,8 +681,9 @@
 */
 
 void
-delete_console_internal (struct console *con, int force,
-			 int called_from_kill_emacs, int from_io_error)
+delete_console_internal (struct console *con, Boolint force,
+			 Boolint called_from_kill_emacs,
+			 Boolint from_io_error)
 {
   /* This function can GC */
   Lisp_Object console;
@@ -1115,10 +1116,10 @@
        (UNUSED (ignored), USED_IF_TTY (flow), meta, quit, console))
 {
   struct console *con = decode_console (console);
-  int meta_key = (!CONSOLE_TTY_P (con) ? 1 :
-		  EQ (meta, Qnil)      ? 0 :
-		  EQ (meta, Qt)        ? 1 :
-		  2);
+  unsigned int meta_key = (!CONSOLE_TTY_P (con) ? 1 :
+			     EQ (meta, Qnil)      ? 0 :
+			     EQ (meta, Qt)        ? 1 :
+			     2);
 
   if (!NILP (quit))
     {
@@ -1133,7 +1134,7 @@
     {
       reset_one_console (con);
       TTY_FLAGS (con).flow_control = !NILP (flow);
-      TTY_FLAGS (con).meta_key = meta_key;
+      TTY_FLAGS (con).meta_key = meta_key & 0x2;
       init_one_console (con);
       MARK_FRAME_CHANGED (XFRAME (CONSOLE_SELECTED_FRAME (con)));
     }
@@ -1337,7 +1338,7 @@
   MARK_LRECORD_AS_LISP_READONLY (I_hate_C);				   \
 									   \
   {									   \
-    int offset = ((char *)symbol_value_forward_forward (I_hate_C)	   \
+    size_t offset = ((char *)symbol_value_forward_forward (I_hate_C)	   \
 		  - (char *)&console_local_flags);			   \
 									   \
     defvar_magic (lname, I_hate_C);					   \
diff -r 046a3f85a39d -r c5889f9bb7f4 src/console.h
--- a/src/console.h	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/console.h	Mon Apr 23 13:43:40 2018 +0100
@@ -138,8 +138,9 @@
 
 enum console_variant get_console_variant (Lisp_Object type);
 
-void delete_console_internal (struct console *con, int force,
-			      int from_kill_emacs, int from_io_error);
+void delete_console_internal (struct console *con, Boolint force,
+			      Boolint from_kill_emacs,
+			      Boolint from_io_error);
 void io_error_delete_console (Lisp_Object console);
 void set_console_last_nonminibuf_frame (struct console *con,
 					Lisp_Object frame);
diff -r 046a3f85a39d -r c5889f9bb7f4 src/data.c
--- a/src/data.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/data.c	Mon Apr 23 13:43:40 2018 +0100
@@ -1200,7 +1200,8 @@
 
       type_checking_assert (FIXNUMP (top) && FIXNUMP (bot));
 
-      return (XFIXNUM (top) << 16) | (XFIXNUM (bot) & 0xffff);
+      return ((UINT_32_BIT) XFIXNUM (top) << 16) |
+	      (UINT_32_BIT) (XFIXNUM (bot) & 0xffff);
     }
 }
 
@@ -1237,7 +1238,7 @@
           return (INT_32_BIT) bignum_to_emacs_int (XBIGNUM_DATA (item));
         }
 #endif
-      return XFIXNUM (item);
+      return (UINT_32_BIT) XFIXNUM (item);
     }
   else
     {
@@ -2924,7 +2925,7 @@
 
   val2 = EMACS_INT_ABS (number2);
       
-  return make_fixnum ((EMACS_INT)((val1 % val2) * sign));
+  return make_fixnum ((EMACS_INT)(val1 % val2) * sign);
 }
 
 DEFUN ("%", Frem, 2, 2, 0, /*
@@ -3146,7 +3147,7 @@
             {
               args_out_of_range_3 (count,
 				   make_bignum_ll (- (long long)(ULONG_MAX)),
-                                   make_bignum_ll (ULONG_MAX));
+                                   make_bignum_ull (ULONG_MAX));
             }
 	  bignum_rshift (scratch_bignum2, XBIGNUM_DATA (value),
 			 bignum_to_ulong (scratch_bignum));
@@ -3158,7 +3159,7 @@
             {
               args_out_of_range_3 (count,
 				   make_bignum_ll (- (long long) (ULONG_MAX)),
-                                   make_bignum_ll (ULONG_MAX));
+                                   make_bignum_ull (ULONG_MAX));
             }
 	  bignum_lshift (scratch_bignum2, XBIGNUM_DATA (value),
 			 bignum_to_ulong (XBIGNUM_DATA (count)));
diff -r 046a3f85a39d -r c5889f9bb7f4 src/debug.c
--- a/src/debug.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/debug.c	Mon Apr 23 13:43:40 2018 +0100
@@ -61,7 +61,7 @@
   if (op == X_LIST || op == X_ACTIVE || op == X_INIT || EQ (class_, Q##item)) \
     {									      \
       if (op == X_ADD || op == X_DELETE || op == X_INIT)		      \
-	active_debug_classes.item = flag;				      \
+	active_debug_classes.item = flag & 1;				      \
       else if (op == X_LIST						      \
 	       || (op == X_ACTIVE && active_debug_classes.item))	      \
 	retval = Fcons (Q##item, retval);				      \
diff -r 046a3f85a39d -r c5889f9bb7f4 src/device.c
--- a/src/device.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/device.c	Mon Apr 23 13:43:40 2018 +0100
@@ -621,7 +621,7 @@
      specify different global resources (there's a property on each X
      server's root window that holds some resources); tough luck for the
      moment. */
-  int first = NILP (get_default_device (type));
+  Boolint first = NILP (get_default_device (type));
 
   GCPRO3 (device, console, name);
 
@@ -778,9 +778,9 @@
 */
 
 void
-delete_device_internal (struct device *d, int force,
-			int called_from_delete_console,
-			int from_io_error)
+delete_device_internal (struct device *d, Boolint force,
+			Boolint called_from_delete_console,
+			Boolint from_io_error)
 {
   /* This function can GC */
   struct console *c;
@@ -1031,7 +1031,8 @@
 */
        (device, rate))
 {
-  CHECK_FIXNUM (rate);
+  /* Nothing greater than 30 bits, please.*/
+  check_integer_range (rate, Qzero, make_fixnum (0x3fffffff));
 
   DEVICE_BAUD_RATE (decode_device (device)) = XFIXNUM (rate);
 
diff -r 046a3f85a39d -r c5889f9bb7f4 src/device.h
--- a/src/device.h	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/device.h	Mon Apr 23 13:43:40 2018 +0100
@@ -101,9 +101,9 @@
 void select_device_1 (Lisp_Object);
 struct device *decode_device (Lisp_Object);
 void handle_asynch_device_change (void);
-void delete_device_internal (struct device *d, int force,
-			     int called_from_delete_console,
-			     int from_io_error);
+void delete_device_internal (struct device *d, Boolint force,
+			     Boolint called_from_delete_console,
+			     Boolint from_io_error);
 void io_error_delete_device (Lisp_Object device);
 Lisp_Object find_nonminibuffer_frame_not_on_device (Lisp_Object device);
 void set_device_selected_frame (struct device *d, Lisp_Object frame);
diff -r 046a3f85a39d -r c5889f9bb7f4 src/doc.c
--- a/src/doc.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/doc.c	Mon Apr 23 13:43:40 2018 +0100
@@ -48,7 +48,7 @@
 {
   Ibyte buf[DOC_MAX_FILENAME_LENGTH+1];
   Ibyte *buffer = buf;
-  int buffer_size = sizeof (buf) - 1, space_left;
+  Bytecount buffer_size = sizeof (buf) - 1, space_left;
   Ibyte *from, *to;
   REGISTER Ibyte *p = buffer;
   Lisp_Object return_me;
@@ -82,7 +82,7 @@
   space_left = buffer_size - (p - buffer);
   while (space_left > 0)
     {
-      int nread;
+      Bytecount nread;
 
       nread = Lstream_read (XLSTREAM (instream), p, space_left);
       if (nread < 0)
@@ -740,8 +740,8 @@
 {
   int fd;
   Ibyte buf[1024 + 1];
-  REGISTER int filled;
-  REGISTER int pos;
+  REGISTER Bytecount filled;
+  REGISTER OFF_T pos;
   REGISTER Ibyte *p, *end;
   Lisp_Object sym, fun, tem;
   Ibyte *name;
@@ -987,7 +987,7 @@
 
   if (!NILP (Ffboundp (sym)))
     {
-      int doc = 0;
+      EMACS_INT doc = 0;
       Lisp_Object fun = XSYMBOL (sym)->function;
       if (CONSP (fun) &&
 	  EQ (XCAR (fun), Qmacro))
@@ -1129,7 +1129,8 @@
       strdata = XSTRING_DATA (string);
       strlength = XSTRING_LENGTH (string);
       strp = strdata + idx;
-      backslashp = (const Ibyte *) memchr (strp, '\\', strlength - idx);
+      backslashp = (const Ibyte *) memchr (strp, '\\', 
+					   max (strlength - idx, 0));
       partlen = backslashp ? backslashp - strp : strlength - idx;
 
       if (changed)
@@ -1159,7 +1160,7 @@
           
           idx += ichar_len ('[');
           strp = strdata + idx;
-          strp = (Ibyte *) memchr (strp, ']', strlength - idx);
+          strp = (Ibyte *) memchr (strp, ']', max (strlength - idx, 0));
  
           if (!strp)
             {
diff -r 046a3f85a39d -r c5889f9bb7f4 src/doprnt.c
--- a/src/doprnt.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/doprnt.c	Mon Apr 23 13:43:40 2018 +0100
@@ -610,7 +610,14 @@
     {
       Bytecount size = ratio_size_in_base (XRATIO_DATA (number),
                                            radixing), len;
-      Ibyte *buffer = alloca_ibytes (size);
+      Ibyte *buffer;
+
+      if (size < 0)
+	{
+	  out_of_memory ("cannot print supplied ratio", Qunbound);
+	}
+
+      buffer = alloca_ibytes (size);
 
       len = ratio_to_string_1 (&buffer, size, XRATIO_DATA (number), radixing,
                                fixnum_to_char_table);
@@ -2404,6 +2411,10 @@
               }
 
             size = bignum_size_decimal (XBIGNUM_DATA (obj));
+	    if (size < 0)
+	      {
+		out_of_memory ("cannot print bignum in decimal", Qunbound);
+	      }
             to_print = alloca_ibytes (size);
             end = to_print + size; 
 
@@ -2452,6 +2463,11 @@
               }
 
             size = bignum_size_octal (XBIGNUM_DATA (obj));
+	    if (size < 0)
+	      {
+		out_of_memory ("cannot print bignum", Qunbound);
+	      }
+
             to_print = alloca_ibytes (size);
             end = to_print + size; 
 
@@ -2506,6 +2522,10 @@
               }
 
             size = bignum_size_binary (XBIGNUM_DATA (obj));
+	    if (size < 0)
+	      {
+		out_of_memory ("cannot print bignum in binary", Qunbound);
+	      }
             to_print = alloca_ibytes (size);
             end = to_print + size; 
 
@@ -2559,6 +2579,10 @@
               }
 
             size = bignum_size_hex (XBIGNUM_DATA (obj));
+	    if (size < 0)
+	      {
+		out_of_memory ("cannot print bignum in hex", Qunbound);
+	      }
             to_print = alloca_ibytes (size);
             end = to_print + size; 
 
@@ -2603,6 +2627,10 @@
               }
 
             size = ratio_size_in_base (XRATIO_DATA (obj), 10);
+	    if (size < 0)
+	      {
+		out_of_memory ("cannot print ratio in decimal", Qunbound);
+	      }
             to_print = alloca_ibytes (size);
             end = to_print + size; 
 
diff -r 046a3f85a39d -r c5889f9bb7f4 src/editfns.c
--- a/src/editfns.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/editfns.c	Mon Apr 23 13:43:40 2018 +0100
@@ -1651,7 +1651,7 @@
   REGISTER Bytecount charlen;
   Ibyte str[MAX_ICHAR_LEN];
   struct buffer *b = decode_buffer (buffer, 1);
-  int cou;
+  Charcount cou;
 
   CHECK_CHAR_COERCE_INT (character);
   if (NILP (count))
@@ -2161,7 +2161,7 @@
 {
   struct buffer *buf;
   Lisp_Object markers = XCDR (data);
-  int local_clip_changed = 0;
+  Boolint local_clip_changed = 0;
 
   buf = XBUFFER (XCAR (data));
   /* someone could have killed the buffer in the meantime ... */
diff -r 046a3f85a39d -r c5889f9bb7f4 src/elhash.c
--- a/src/elhash.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/elhash.c	Mon Apr 23 13:43:40 2018 +0100
@@ -2307,7 +2307,8 @@
 /* Return a hash value for an array of Lisp_Objects of size SIZE. */
 
 Hashcode
-internal_array_hash (Lisp_Object *arr, int size, int depth, Boolint equalp)
+internal_array_hash (Lisp_Object *arr, Elemcount size, int depth,
+		     Boolint equalp)
 {
   int i;
   Hashcode hash = 0;
diff -r 046a3f85a39d -r c5889f9bb7f4 src/filelock.c
--- a/src/filelock.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/filelock.c	Mon Apr 23 13:43:40 2018 +0100
@@ -89,7 +89,7 @@
 
 /* When we read the info back, we might need this much more,
    enough for decimal representation plus null.  */
-#define LOCK_PID_MAX (4 * sizeof (pid_t))
+#define LOCK_PID_MAX (4 * (int) (sizeof (pid_t)))
 
 /* Free the two dynamically-allocated pieces in PTR.  */
 #define FREE_LOCK_INFO(i) do {			\
@@ -109,7 +109,7 @@
 {
   Ibyte *file_name = XSTRING_DATA (fn);
   Ibyte *p;
-  Bytecount dirlen;
+  size_t dirlen;
 
   for (p = file_name + XSTRING_LENGTH (fn) - 1;
        p > file_name && !IS_ANY_SEP (p[-1]);
@@ -173,11 +173,11 @@
 current_lock_owner (lock_info_type *owner, Ibyte *lfname)
 {
   /* Does not GC. */
-  int len, ret;
-  int local_owner = 0;
+  Bytecount len;
+  int local_owner = 0, ret;
   Ibyte *at, *dot;
   Ibyte *lfinfo = 0;
-  int bufsize = 50;
+  size_t bufsize = 50;
   /* Read arbitrarily-long contents of symlink.  Similar code in
      file-symlink-p in fileio.c.  */
   do
@@ -186,7 +186,7 @@
       lfinfo = (Ibyte *) xrealloc (lfinfo, bufsize);
       len = qxe_readlink (lfname, lfinfo, bufsize);
     }
-  while (len >= bufsize);
+  while (len >= (Bytecount) bufsize);
 
   /* If nonexistent lock file, all is well; otherwise, got strange error. */
   if (len == -1)
diff -r 046a3f85a39d -r c5889f9bb7f4 src/indent.c
--- a/src/indent.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/indent.c	Mon Apr 23 13:43:40 2018 +0100
@@ -49,7 +49,7 @@
 
    Some things set last_known_column_point to -1
    to mark the memoized value as invalid */
-static int last_known_column;
+static Charcount last_known_column;
 
 /* Last buffer searched by current_column */
 static struct buffer *last_known_column_buffer;
@@ -120,13 +120,13 @@
   last_known_column_point = -1;
 }
 
-int
-column_at_point (struct buffer *buf, Charbpos init_pos, int cur_col)
+Charcount
+column_at_point (struct buffer *buf, Charbpos init_pos, Charcount cur_col)
 {
-  int col;
-  int tab_seen;
-  int tab_width = XFIXNUM (buf->tab_width);
-  int post_tab;
+  Charcount col;
+  Charcount tab_seen;
+  Charcount tab_width = XFIXNUM (buf->tab_width);
+  Charcount post_tab;
   Charbpos pos = init_pos;
   Ichar c;
 
@@ -187,12 +187,12 @@
   return col;
 }
 
-int
-string_column_at_point (Lisp_Object s, Charbpos init_pos, int tab_width)
+Charcount
+string_column_at_point (Lisp_Object s, Charbpos init_pos, Charcount tab_width)
 {
-  int col;
-  int tab_seen;
-  int post_tab;
+  Charcount col;
+  Charcount tab_seen;
+  Charcount post_tab;
   Charbpos pos = init_pos;
   Ichar c;
 
@@ -230,7 +230,7 @@
   return col;
 }
 
-int
+Charcount
 current_column (struct buffer *buf)
 {
   if (buf == last_known_column_buffer
@@ -268,10 +268,10 @@
        (column, minimum, buffer))
 {
   /* This function can GC */
-  int mincol;
-  int fromcol;
+  Charcount mincol;
+  Charcount fromcol;
   struct buffer *buf = decode_buffer (buffer, 0);
-  int tab_width = XFIXNUM (buf->tab_width);
+  Charcount tab_width = XFIXNUM (buf->tab_width);
   Charbpos opoint = 0;
 
   CHECK_FIXNUM (column);
@@ -305,7 +305,7 @@
 
   if (indent_tabs_mode)
     {
-      int n = mincol / tab_width - fromcol / tab_width;
+      Charcount n = mincol / tab_width - fromcol / tab_width;
       if (n != 0)
 	{
 	  Finsert_char (make_char ('\t'), make_fixnum (n), Qnil, buffer);
@@ -328,13 +328,13 @@
   return make_fixnum (mincol);
 }
 
-int
+Charcount
 byte_spaces_at_point (struct buffer *b, Bytebpos byte_pos)
 {
   Bytebpos byte_end = BYTE_BUF_ZV (b);
-  int col = 0;
+  Charcount col = 0;
   Ichar c;
-  int tab_width = XFIXNUM (b->tab_width);
+  Charcount tab_width = XFIXNUM (b->tab_width);
 
   if (tab_width <= 0 || tab_width > 1000)
     tab_width = 8;
@@ -392,19 +392,26 @@
   /* This function can GC */
   Charbpos pos;
   struct buffer *buf = decode_buffer (buffer, 0);
-  int col = current_column (buf);
-  int goal;
+  Charcount col = current_column (buf);
+  Charcount goal;
   Charbpos end;
-  int tab_width = XFIXNUM (buf->tab_width);
+  Charcount tab_width = XFIXNUM (buf->tab_width);
 
-  int prev_col = 0;
+  Charcount prev_col = 0;
   Ichar c = 0;
 
   buffer = wrap_buffer (buf);
   if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
 
-  check_integer_range (column, Qzero, make_fixnum (MOST_POSITIVE_FIXNUM));
-  goal = XFIXNUM (column);
+  CHECK_NATNUM (column);
+  if (BIGNUMP (column))
+    {
+      goal = 1 + MOST_POSITIVE_FIXNUM;
+    }
+  else
+    {
+      goal = XFIXNUM (column);
+    }
 
  retry:
   pos = BUF_PT (buf);
@@ -526,7 +533,7 @@
 {
   Lisp_Object charbpos, hpos, vpos, prevhpos, contin;
   struct position *pos;
-  int hscroll, tab_offset;
+  Charcount hscroll, tab_offset;
   struct window *w = decode_window (window);
 
   CHECK_FIXNUM_COERCE_MARKER (from);
@@ -694,7 +701,7 @@
 {
   Charbpos charbpos;
   Charbpos orig;
-  int selected;
+  Boolint selected;
   int *vpos, *vpix;
   int value=0;
   struct window *w;
@@ -877,9 +884,9 @@
 {
   Charbpos charbpos;
   Charbpos orig;
-  int selected;
+  Boolint selected;
   int motion;
-  int howto;
+  int howto = 0;
   struct window *w;
 
   if (NILP (window))
@@ -895,7 +902,19 @@
   orig = selected ? BUF_PT (XBUFFER (w->buffer))
                   : marker_position (w->pointm[CURRENT_DISP]);
 
-  howto = FIXNUMP (how) ? XFIXNUM (how) : 0;
+  if (INTEGERP (how))
+    {
+      if (FIXNUMP (how))
+	{
+	  howto = XFIXNUM (how) < 0 ? -1 : (XFIXNUM (how) > 0);
+	}
+#ifdef HAVE_BIGNUM
+      else
+	{
+	  howto = bignum_sign (XBIGNUM_DATA (how));
+	}
+#endif
+    }
 
   charbpos = vmotion_pixels (window, orig, XFIXNUM (pixels), howto, &motion);
 
diff -r 046a3f85a39d -r c5889f9bb7f4 src/lisp-disunion.h
--- a/src/lisp-disunion.h	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/lisp-disunion.h	Mon Apr 23 13:43:40 2018 +0100
@@ -83,7 +83,7 @@
 #define XPNTRVAL(x) (x) /* This depends on Lisp_Type_Record == 0 */
 /* A character is always >= 0, so get 30 bits out of it by treating it as
    unsigned */
-#define XCHARVAL(x) ((EMACS_UINT)(x) >> GCBITS)
+#define XCHARVAL(x) ((EMACS_UINT)(x) >> (EMACS_UINT) GCBITS)
 #define XREALFIXNUM(x) ((x) >> FIXNUM_GCBITS)
 #define XUINT(x) ((EMACS_UINT)(x) >> FIXNUM_GCBITS)
 
diff -r 046a3f85a39d -r c5889f9bb7f4 src/lisp.h
--- a/src/lisp.h	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/lisp.h	Mon Apr 23 13:43:40 2018 +0100
@@ -1447,7 +1447,7 @@
 
 #ifdef USE_GCC_EXTENDED_EXPRESSION_SYNTAX
 #define ALLOCA(size)						\
-  ({ Bytecount temp_alloca_size;				\
+  ({ size_t temp_alloca_size;					\
      REGEX_MALLOC_CHECK ();					\
      temp_alloca_size = (size);					\
      temp_alloca_size  > MAX_ALLOCA_VS_C_ALLOCA ?		\
@@ -2848,7 +2848,7 @@
 /* WARNING: If you modify an existing string, you must call
    bump_string_modiff() afterwards. */
 #define XSET_STRING_ASCII_BEGIN(s, val) \
-  ((void) (XSTRING (s)->u.v.ascii_begin = (val)))
+  ((void) (XSTRING (s)->u.v.ascii_begin = (val) & MAX_STRING_ASCII_BEGIN))
 #define XSTRING_FORMAT(s) FORMAT_DEFAULT
 
 #define XSTRING_MODIFFP(s) (XSTRING (s)->u.v.modiffp + 0)
@@ -3277,12 +3277,27 @@
    character. */
 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x))
 
+#define XCHAR_OR_CHAR_INT(x) XCHAR_OR_CHAR_INT_1 (x, __FILE__, __LINE__)
+
 DECLARE_INLINE_HEADER (
 Ichar
-XCHAR_OR_CHAR_INT (Lisp_Object obj)
+XCHAR_OR_CHAR_INT_1 (Lisp_Object obj, const Ascbyte *file, int line)
 )
 {
-  return CHARP (obj) ? XCHAR (obj) : XFIXNUM (obj);
+  if (CHARP (obj))
+    {
+      return XCHARVAL (obj);
+    }
+  if (FIXNUMP (obj))
+    {
+      EMACS_INT ival = XREALFIXNUM (obj);
+      if (valid_ichar_p (ival))
+	{
+	  return (Ichar) ival;
+	}
+    }
+  assert_at_line (CHARP (obj) || CHAR_INTP (obj), file, line);
+  return (Ichar) -1;
 }
 
 /* Signal an error if CH is not a valid character or integer Lisp_Object.
@@ -3294,7 +3309,7 @@
   if (CHARP (x))				\
      ;						\
   else if (CHAR_INTP (x))			\
-    x = make_char (XFIXNUM (x));			\
+    x = make_char ((Ichar) XREALFIXNUM (x));	\
   else						\
     x = wrong_type_argument (Qcharacterp, x);	\
 } while (0)
@@ -4003,8 +4018,14 @@
 /*				 hashing				*/
 /************************************************************************/
 
-/* #### for a 64-bit machine, we should substitute a prime just over 2^32 */
-#define GOOD_HASH 65599 /* prime number just over 2^16; Dragon book, p. 435 */
+#if SIZEOF_EMACS_INT < 8
+#define GOOD_HASH ((Hashcode) 65599) /* prime number just over 2^16;
+					Dragon book, p. 435 */
+
+#else
+#define GOOD_HASH ((Hashcode) 4294967311UL) /* prime number just over 2^32 */
+#endif
+
 #define HASH2(a,b)               (GOOD_HASH * (a)                     + (b))
 #define HASH3(a,b,c)             (GOOD_HASH * HASH2 (a,b)             + (c))
 #define HASH4(a,b,c,d)           (GOOD_HASH * HASH3 (a,b,c)           + (d))
@@ -4014,10 +4035,10 @@
 #define HASH8(a,b,c,d,e,f,g,h)   (GOOD_HASH * HASH7 (a,b,c,d,e,f,g)   + (h))
 #define HASH9(a,b,c,d,e,f,g,h,i) (GOOD_HASH * HASH8 (a,b,c,d,e,f,g,h) + (i))
 
-#define LISP_HASH(obj) ((unsigned long) STORE_LISP_IN_VOID (obj))
+#define LISP_HASH(obj) ((Hashcode) STORE_LISP_IN_VOID (obj))
 Hashcode memory_hash (const void *xv, Bytecount size);
 Hashcode internal_hash (Lisp_Object obj, int depth, Boolint equalp);
-Hashcode internal_array_hash (Lisp_Object *arr, int size, int depth,
+Hashcode internal_array_hash (Lisp_Object *arr, Elemcount size, int depth,
                               Boolint equalp);
 
 
@@ -4075,7 +4096,7 @@
 {
   struct gcpro *next;
   const Lisp_Object *var;	/* Address of first protected variable */
-  int nvars;			/* Number of consecutive protected variables */
+  Elemcount nvars;		/* Number of consecutive protected variables */
 #if defined (__cplusplus) && defined (ERROR_CHECK_GC)
   /* Try to catch GCPRO without UNGCPRO, or vice-versa.  G++ complains (at
      least with sufficient numbers of warnings enabled, i.e. -Weffc++) if a
@@ -5632,10 +5653,10 @@
 EXFUN (Findent_to, 3);
 EXFUN (Fvertical_motion, 3);
 
-int byte_spaces_at_point (struct buffer *, Bytebpos);
-int column_at_point (struct buffer *, Charbpos, int);
-int string_column_at_point (Lisp_Object, Charbpos, int);
-int current_column (struct buffer *);
+Charcount byte_spaces_at_point (struct buffer *, Bytebpos);
+Charcount column_at_point (struct buffer *, Charbpos, Charcount);
+Charcount string_column_at_point (Lisp_Object, Charbpos, Charcount);
+Charcount current_column (struct buffer *);
 void invalidate_current_column (void);
 Charbpos vmotion (struct window *, Charbpos, int, int *);
 Charbpos vmotion_pixels (Lisp_Object, Charbpos, int, int, int *);
@@ -5654,7 +5675,7 @@
   if (*len < 0)
     {
       if (nonreloc)
-	*len = strlen ((const Chbyte *) nonreloc) - offset;
+	*len = (Bytecount) strlen ((const Chbyte *) nonreloc) - offset;
       else
 	*len = XSTRING_LENGTH (reloc) - offset;
     }
@@ -5878,7 +5899,7 @@
 void debug_print (Lisp_Object);
 void debug_p4 (Lisp_Object obj);
 void debug_p3 (Lisp_Object obj);
-void debug_short_backtrace (int);
+void debug_short_backtrace (EMACS_INT);
 void debug_backtrace (void);
 MODULE_API Bytecount write_lisp_string (Lisp_Object stream, Lisp_Object string,
 					Bytecount offset, Bytecount len);
@@ -5899,7 +5920,8 @@
 {
   /* This function can GC. We'd like to qxestrlen, but that's not yet
      available in this file. */
-  return write_string_1 (stream, str, strlen ((const char *) str));
+  return write_string_1 (stream, str,
+			 (Bytecount) strlen ((const char *) str));
 }
 /* Same goes for this function. */
 DECLARE_INLINE_HEADER (
@@ -5909,7 +5931,7 @@
   /* This function can GC. We'd like to qxestrlen, but that's not yet
      available in this file. */
   return write_string_1 (stream, (const Ibyte *) str,
-			 strlen ((const char *) str));
+			 (Bytecount) strlen ((const char *) str));
 }
 /* Same goes for this function. */
 DECLARE_INLINE_HEADER (
@@ -5917,7 +5939,8 @@
 )
 {
   /* This function can GC. */
-  return write_string_1 (stream, (const Ibyte *) str, strlen ((char *) str));
+  return write_string_1 (stream, (const Ibyte *) str,
+			 (Bytecount) strlen ((char *) str));
 }
 Bytecount write_eistring (Lisp_Object stream, const Eistring *ei);
 
@@ -6031,7 +6054,8 @@
 Bytebpos byte_find_next_newline_no_quit (struct buffer *, Bytebpos, int);
 Bytecount byte_find_next_ichar_in_string (Lisp_Object, Ichar, Bytecount,
 					 EMACS_INT);
-Charbpos find_before_next_newline (struct buffer *, Charbpos, Charbpos, int);
+Charbpos find_before_next_newline (struct buffer *, Charbpos, Charbpos,
+				   EMACS_INT);
 struct re_pattern_buffer *compile_pattern (Lisp_Object pattern,
 					   struct re_registers *regp,
 					   Lisp_Object translate,
@@ -6125,7 +6149,7 @@
 extern Lisp_Object Vobarray;
 
 /* Defined in syntax.c */
-Charbpos scan_words (struct buffer *, Charbpos, int);
+Charbpos scan_words (struct buffer *, Charbpos, EMACS_INT);
 EXFUN (Fchar_syntax, 2);
 EXFUN (Fforward_word, 2);
 extern Lisp_Object Vstandard_syntax_table;
@@ -6287,7 +6311,7 @@
 
 DECLARE_INLINE_HEADER (Bytecount qxestrlen (const Ibyte *s))
 {
-  return strlen ((const Chbyte *) s);
+  return (Bytecount) strlen ((const Chbyte *) s);
 }
 
 DECLARE_INLINE_HEADER (Charcount qxestrcharlen (const Ibyte *s))
@@ -6566,7 +6590,7 @@
 /* Defined in undo.c */
 EXFUN (Fundo_boundary, 0);
 
-Lisp_Object truncate_undo_list (Lisp_Object, int, int);
+Lisp_Object truncate_undo_list (Lisp_Object, Fixnum, Fixnum);
 void record_extent (Lisp_Object, int);
 void record_insert (struct buffer *, Charbpos, Charcount);
 void record_delete (struct buffer *, Charbpos, Charcount);
@@ -6732,7 +6756,7 @@
   /* This function can GC */
   str = ASCGETTEXT (str);
   write_string_1 (stream, (const Ibyte *) str,
-                  strlen ((const Ascbyte *) str));
+                  (Bytecount) strlen ((const Ascbyte *) str));
 }
 
 #define write_msg_string write_msg_ascstring
diff -r 046a3f85a39d -r c5889f9bb7f4 src/lrecord.h
--- a/src/lrecord.h	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/lrecord.h	Mon Apr 23 13:43:40 2018 +0100
@@ -266,7 +266,7 @@
   SLI_header->type = (imp)->lrecord_type_index;				\
   SLI_header->lisp_readonly = 0;					\
   SLI_header->free = 0;							\
-  SLI_header->uid = lrecord_uid_counter[(imp)->lrecord_type_index]++;   \
+  SLI_header->uid = lrecord_uid_counter[(imp)->lrecord_type_index]++;	\
 } while (0)
 #else /* not NEW_GC */
 #define set_lheader_implementation(header,imp) do {			\
@@ -671,7 +671,7 @@
 void inc_lrecord_stats (Bytecount size, const struct lrecord_header *h);
 void dec_lrecord_stats (Bytecount size_including_overhead, 
 			const struct lrecord_header *h);
-int lrecord_stats_heap_size (void);
+Bytecount lrecord_stats_heap_size (void);
 #endif /* ALLOC_TYPE_STATS */
 
 /* Tell mc-alloc how to call a finalizer. */
@@ -2094,10 +2094,10 @@
 MODULE_API Lisp_Object alloc_lrecord (const struct lrecord_implementation *imp);
 Lisp_Object noseeum_alloc_lrecord (const struct lrecord_implementation *imp);
 
-MODULE_API Lisp_Object alloc_lrecord_array (int elemcount,
+MODULE_API Lisp_Object alloc_lrecord_array (Elemcount elemcount,
 				 const struct lrecord_implementation *imp);
 MODULE_API Lisp_Object alloc_sized_lrecord_array (Bytecount size,
-						  int elemcount,
+						  Elemcount elemcount,
 						  const struct lrecord_implementation *imp);
 
 #endif /* NEW_GC */
diff -r 046a3f85a39d -r c5889f9bb7f4 src/number.h
--- a/src/number.h	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/number.h	Mon Apr 23 13:43:40 2018 +0100
@@ -220,7 +220,7 @@
    NATNUMP. */
 
 #ifdef HAVE_BIGNUM
-#define NATNUMP(x) ((FIXNUMP (x) && XFIXNUM (x) >= 0) || \
+#define NATNUMP(x) ((FIXNUMP (x) && XREALFIXNUM (x) >= 0) || \
 		    (BIGNUMP (x) && bignum_sign (XBIGNUM_DATA (x)) >= 0))
 #else
 #define NATNUMP(x) (FIXNUMP (x) && XFIXNUM (x) >= 0)
diff -r 046a3f85a39d -r c5889f9bb7f4 src/print.c
--- a/src/print.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/print.c	Mon Apr 23 13:43:40 2018 +0100
@@ -2983,9 +2983,9 @@
 /* Do a "short" backtrace. */
 
 void
-debug_short_backtrace (int length)
+debug_short_backtrace (EMACS_INT length)
 {
-  int first = 1;
+  Fixnum first = 1;
   struct backtrace *bt = backtrace_list;
 
   debug_out ("   [");
diff -r 046a3f85a39d -r c5889f9bb7f4 src/search.c
--- a/src/search.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/search.c	Mon Apr 23 13:43:40 2018 +0100
@@ -924,7 +924,7 @@
    find_next_newline (...)-1, because you might hit TO.  */
 Charbpos
 find_before_next_newline (struct buffer *buf, Charbpos from, Charbpos to,
-			  int count)
+			  EMACS_INT count)
 {
   EMACS_INT shortage;
   Charbpos pos = scan_buffer (buf, '\n', from, to, count, &shortage, 1);
diff -r 046a3f85a39d -r c5889f9bb7f4 src/syntax.c
--- a/src/syntax.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/syntax.c	Mon Apr 23 13:43:40 2018 +0100
@@ -750,7 +750,7 @@
    COUNT negative means scan backward and stop at word beginning.  */
 
 Charbpos
-scan_words (struct buffer *buf, Charbpos from, int count)
+scan_words (struct buffer *buf, Charbpos from, EMACS_INT count)
 {
   Charbpos limit = count > 0 ? BUF_ZV (buf) : BUF_BEGV (buf);
   Ichar ch0, ch1;
diff -r 046a3f85a39d -r c5889f9bb7f4 src/syntax.h
--- a/src/syntax.h	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/syntax.h	Mon Apr 23 13:43:40 2018 +0100
@@ -142,7 +142,7 @@
 /* Return the syntax code for a particular character and mirror table. */
 
 DECLARE_INLINE_HEADER (
-int
+EMACS_INT
 SYNTAX_CODE (Lisp_Object table, Ichar c)
 )
 {
diff -r 046a3f85a39d -r c5889f9bb7f4 src/sysdep.c
--- a/src/sysdep.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/sysdep.c	Mon Apr 23 13:43:40 2018 +0100
@@ -204,7 +204,7 @@
 #ifdef NEED_SYNC_PROCESS_CODE /* #### Used only on super-ancient systems */
 
 static void
-wait_for_termination (int pid)
+wait_for_termination (pid_t pid)
 {
   /* #### With the new improved SIGCHLD handling stuff, there is much
      less danger of race conditions and some of the comments below
@@ -608,7 +608,7 @@
 #else /* not WIN32_NATIVE */
 
   {
-    int pid;
+    pid_t pid;
     struct save_signal saved_handlers[5];
 
     saved_handlers[0].code = SIGINT;
@@ -663,7 +663,7 @@
 {
 #if defined (SIGTSTP)
   {
-    int pgrp = EMACS_GET_PROCESS_GROUP ();
+    pid_t pgrp = EMACS_GET_PROCESS_GROUP ();
     EMACS_KILLPG (pgrp, SIGTSTP);
   }
 
@@ -681,9 +681,9 @@
 void
 sys_suspend_process (
 #ifdef SIGTSTP
-		     int process
+		     pid_t process
 #else
-		     int UNUSED (process)
+		     pid_t UNUSED (process)
 #endif
 		     )
 {
@@ -929,7 +929,7 @@
 
 #if defined (FIOSSAIOOWN)
   { /* HPUX stuff */
-    int owner = getpid ();
+    pid_t owner = getpid ();
     int ioctl_status;
     if (DEVICE_TTY_P (d))
 	{
@@ -2904,10 +2904,10 @@
 }
 
 #if defined (HAVE_READLINK)
-int
+ssize_t
 qxe_readlink (const Ibyte *path, Ibyte *buf, size_t bufsiz)
 {
-  int retval;
+  Bytecount retval;
   Extbyte *pathout;
 
   PATHNAME_CONVERT_OUT (path, pathout);
diff -r 046a3f85a39d -r c5889f9bb7f4 src/sysfile.h
--- a/src/sysfile.h	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/sysfile.h	Mon Apr 23 13:43:40 2018 +0100
@@ -383,7 +383,7 @@
 int qxe_access (const Ibyte *path, int mode);
 int qxe_eaccess (const Ibyte *path, int mode);
 int qxe_lstat (const Ibyte *path, struct stat *buf);
-int qxe_readlink (const Ibyte *path, Ibyte *buf, size_t bufsiz);
+ssize_t qxe_readlink (const Ibyte *path, Ibyte *buf, size_t bufsiz);
 int qxe_fstat (int fd, struct stat *buf);
 int qxe_stat (const Ibyte *path, struct stat *buf);
 Ibyte *qxe_realpath (const Ibyte *path, Ibyte resolved_path [],
diff -r 046a3f85a39d -r c5889f9bb7f4 src/text.c
--- a/src/text.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/text.c	Mon Apr 23 13:43:40 2018 +0100
@@ -2678,8 +2678,8 @@
   return changedp ? newp - newdata : 0;
 }
 
-int
-eifind_large_enough_buffer (int oldbufsize, int needed_size)
+Bytecount
+eifind_large_enough_buffer (Bytecount oldbufsize, Bytecount needed_size)
 {
   while (oldbufsize < needed_size)
     {
diff -r 046a3f85a39d -r c5889f9bb7f4 src/text.h
--- a/src/text.h	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/text.h	Mon Apr 23 13:43:40 2018 +0100
@@ -1047,9 +1047,9 @@
 )
 {
   if (dfc_coding_system_is_unicode (codesys))
-    return sizeof (wchar_t) * wcslen ((wchar_t *) ptr);
+    return (Bytecount) (sizeof (wchar_t) * wcslen ((wchar_t *) ptr));
   else
-    return strlen ((char *) ptr);
+    return (Bytecount) strlen ((char *) ptr);
 }
 
 
@@ -1331,9 +1331,8 @@
 #ifdef ERROR_CHECK_TEXT
 #define ASSERT_ASCTEXT_ASCII_LEN(ptr, len)			\
 do {								\
-  int aia2;							\
+  size_t aia2, aia2len = (len);					\
   const Ascbyte *aia2ptr = (ptr);				\
-  int aia2len = (len);						\
 								\
   for (aia2 = 0; aia2 < aia2len; aia2++)			\
     assert (aia2ptr[aia2] >= 0x00 && aia2ptr[aia2] < 0x7F);	\
@@ -2694,7 +2693,7 @@
   Bytecount max_size_allocated_;
   Bytecount bytelen_;
   Charcount charlen_;
-  int mallocp_;
+  Boolint mallocp_;
 
   Extbyte *extdata_;
   Bytecount extlen_;
@@ -2757,17 +2756,17 @@
 
 #define EI_ALLOC(ei, newbytelen, newcharlen, newz)			\
 do {									\
-  int ei1oldeibytelen = (ei)->bytelen_;					\
+  Bytecount ei1oldeibytelen = (ei)->bytelen_;				\
 									\
   (ei)->charlen_ = (newcharlen);					\
   (ei)->bytelen_ = (newbytelen);					\
 									\
   if (ei1oldeibytelen != (ei)->bytelen_)				\
     {									\
-      int ei1newsize = (ei)->max_size_allocated_;			\
+      Bytecount ei1newsize = (ei)->max_size_allocated_;			\
       while (ei1newsize < (ei)->bytelen_ + 1)				\
 	{								\
-	  ei1newsize = (int) (ei1newsize * 1.5);			\
+	  ei1newsize = (Bytecount) (ei1newsize * 1.5);			\
 	  if (ei1newsize < 32)						\
 	    ei1newsize = 32;						\
 	}								\
@@ -2816,13 +2815,13 @@
 #define eicpy_lstr_off(ei, lisp_string, off, charoff, len, charlen)	\
 do {									\
   Lisp_Object ei23lstr = (lisp_string);					\
-  int ei23off = (off);							\
-  int ei23charoff = (charoff);						\
-  int ei23len = (len);							\
-  int ei23charlen = (charlen);						\
+  Bytecount ei23off = (off);						\
+  Charcount ei23charoff = (charoff);					\
+  Bytecount ei23len = (len);						\
+  Charcount ei23charlen = (charlen);					\
   const Ibyte *ei23data = XSTRING_DATA (ei23lstr);			\
 									\
-  int ei23oldbytelen = (ei)->bytelen_;					\
+  Bytecount ei23oldbytelen = (ei)->bytelen_;				\
 									\
   eifixup_byte (ei23data, ei23off, ei23charoff);			\
   eifixup_bytechar (ei23data + ei23off, ei23len, ei23charlen);		\
@@ -2834,7 +2833,7 @@
 do {									\
   const Ibyte *ei12ptr = (ptr);						\
   Internal_Format ei12fmt = (fmt);					\
-  int ei12len = (len);							\
+  Bytecount ei12len = (len);						\
   assert (ei12fmt == FORMAT_DEFAULT);					\
   EI_ALLOC_AND_COPY (ei, ei12ptr, ei12len,				\
 		     bytecount_to_charcount (ei12ptr, ei12len));	\
@@ -2871,7 +2870,7 @@
 #define eicpy_ascii_len(ei, ascstr, c_len)	\
 do {						\
   const Ascbyte *ei6 = (ascstr);		\
-  int ei6len = (c_len);				\
+  Bytecount ei6len = (c_len);				\
 						\
   ASSERT_ASCTEXT_ASCII_LEN (ei6, ei6len);	\
   eicpy_ext_len (ei, ei6, ei6len, Qbinary);	\
@@ -2880,7 +2879,7 @@
 #define eicpy_ext_len(ei, extdata, extlen, codesys)			\
 do {									\
   const Extbyte *ei7 = (extdata);					\
-  int ei7len = (extlen);						\
+  Bytecount ei7len = (extlen);						\
 									\
   TO_INTERNAL_FORMAT (DATA, (ei7, ei7len),				\
 		      ALLOCA, ((ei)->data_, (ei)->bytelen_),		\
@@ -2914,10 +2913,10 @@
 #define eimake_string_off(eistr, off, charoff, len, charlen)		\
 do {									\
   Lisp_Object ei24lstr;							\
-  int ei24off = (off);							\
-  int ei24charoff = (charoff);						\
-  int ei24len = (len);							\
-  int ei24charlen = (charlen);						\
+  Bytecount ei24off = (off);						\
+  Charcount ei24charoff = (charoff);					\
+  Bytecount ei24len = (len);						\
+  Charcount ei24charlen = (charlen);					\
 									\
   eifixup_byte ((eistr)->data_, ei24off, ei24charoff);			\
   eifixup_byte ((eistr)->data_ + ei24off, ei24len, ei24charlen);	\
@@ -2966,7 +2965,8 @@
     eiinit (ei);				\
 } while (0)
 
-int eifind_large_enough_buffer (int oldbufsize, int needed_size);
+Bytecount eifind_large_enough_buffer (Bytecount oldbufsize,
+				      Bytecount needed_size);
 void eito_malloc_1 (Eistring *ei);
 
 #define eito_malloc(ei) eito_malloc_1 (ei)
@@ -3044,7 +3044,7 @@
 					     Charcount n))
 {
   Ibyte *pos = eistr->data_ + bytepos;
-  int i;
+  Charcount i;
 
   text_checking_assert (bytepos >= 0 && bytepos <= eistr->bytelen_);
   text_checking_assert (n >= 0 && n <= eistr->charlen_);
@@ -3078,12 +3078,12 @@
 
 #define eicat_1(ei, data, bytelen, charlen)		\
 do {							\
-  int ei14oldeibytelen = (ei)->bytelen_;		\
-  int ei14bytelen = (bytelen);				\
+  Bytecount ei14oldeibytelen = (ei)->bytelen_;		\
+  Bytecount ei14bytelen = (bytelen);			\
   EI_ALLOC (ei, (ei)->bytelen_ + ei14bytelen,		\
 	    (ei)->charlen_ + (charlen), 1);		\
   memcpy ((ei)->data_ + ei14oldeibytelen, (data),	\
-	  ei14bytelen);					\
+	  (size_t) ei14bytelen);			\
 } while (0)
 
 #define eicat_ei(ei, ei2)					\
@@ -3095,16 +3095,17 @@
 #define eicat_ascii(ei, ascstr)					\
 do {								\
   const Ascbyte *ei15 = (ascstr);				\
-  int ei15len = strlen (ei15);					\
+  size_t ei15len = strlen (ei15);				\
 								\
   ASSERT_ASCTEXT_ASCII_LEN (ei15, ei15len);			\
   eicat_1 (ei, ei15, ei15len,					\
-           bytecount_to_charcount ((Ibyte *) ei15, ei15len));	\
+           bytecount_to_charcount ((Ibyte *) ei15,		\
+				   (Bytecount) ei15len));	\
 } while (0)
 
 #define eicat_raw(ei, data, len)			\
 do {							\
-  int ei16len = (len);					\
+  Bytecount ei16len = (len);				\
   const Ibyte *ei16data = (data);			\
   eicat_1 (ei, ei16data, ei16len,			\
            bytecount_to_charcount (ei16data, ei16len));	\
@@ -3139,15 +3140,15 @@
 
 #define eisub_1(ei, off, charoff, len, charlen, src, srclen, srccharlen) \
 do {									 \
-  int ei18off = (off);							 \
-  int ei18charoff = (charoff);						 \
-  int ei18len = (len);							 \
-  int ei18charlen = (charlen);						 \
+  Bytecount ei18off = (off);						 \
+  Charcount ei18charoff = (charoff);					 \
+  Bytecount ei18len = (len);						 \
+  Charcount ei18charlen = (charlen);					 \
   Ibyte *ei18src = (Ibyte *) (src);					 \
-  int ei18srclen = (srclen);						 \
-  int ei18srccharlen = (srccharlen);					 \
+  Bytecount ei18srclen = (srclen);					 \
+  Charcount ei18srccharlen = (srccharlen);				 \
 									 \
-  int ei18oldeibytelen = (ei)->bytelen_;				 \
+  Bytecount ei18oldeibytelen = (ei)->bytelen_;				 \
 									 \
   eifixup_bytechar ((ei)->data_, ei18off, ei18charoff);			 \
   eifixup_bytechar ((ei)->data_ + ei18off, ei18len, ei18charlen);	 \
@@ -3174,7 +3175,7 @@
 #define eisub_ascii(ei, off, charoff, len, charlen, ascstr)	\
 do {								\
   const Ascbyte *ei20 = (ascstr);				\
-  int ei20len = strlen (ei20);					\
+  Bytecount ei20len = (Bytecount) strlen (ei20);		\
   ASSERT_ASCTEXT_ASCII_LEN (ei20, ei20len);			\
   eisub_1 (ei, off, charoff, len, charlen, ei20, ei20len, -1);	\
 } while (0)
@@ -3315,8 +3316,9 @@
   int ei11new_allocmax = (ei)->charlen_ * MAX_ICHAR_LEN + 1;		\
   Ibyte *ei11storage =							\
      (Ibyte *) alloca_ibytes (ei11new_allocmax);			\
-  int ei11newlen = eistr_casefiddle_1 ((ei)->data_, (ei)->bytelen_,	\
-				       ei11storage, downp);		\
+  Bytecount ei11newlen = eistr_casefiddle_1 ((ei)->data_,		\
+					     (ei)->bytelen_,		\
+					     ei11storage, downp);	\
 									\
   if (ei11newlen)							\
     {									\
diff -r 046a3f85a39d -r c5889f9bb7f4 src/undo.c
--- a/src/undo.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/undo.c	Mon Apr 23 13:43:40 2018 +0100
@@ -250,10 +250,10 @@
    undo-high-threshold.  */
 
 Lisp_Object
-truncate_undo_list (Lisp_Object list, int minsize, int maxsize)
+truncate_undo_list (Lisp_Object list, Fixnum minsize, Fixnum maxsize)
 {
   Lisp_Object prev, next, last_boundary;
-  int size_so_far = 0;
+  Fixnum size_so_far = 0;
 
   if (!(minsize > 0 || maxsize > 0))
     return list;
diff -r 046a3f85a39d -r c5889f9bb7f4 src/unicode.c
--- a/src/unicode.c	Sat Apr 21 16:49:20 2018 +0100
+++ b/src/unicode.c	Mon Apr 23 13:43:40 2018 +0100
@@ -1644,7 +1644,8 @@
 
   write_ascstring (printcharfun,
 		   "#<INTERNAL OBJECT (XEmacs bug?) (precedence-array)");
-  write_fmt_string (printcharfun, " length=%d", Dynarr_length (data->precdyn));
+  write_fmt_string (printcharfun, " length=%ld",
+		    Dynarr_length (data->precdyn));
   for (i = 0; i < Dynarr_length (data->precdyn); i++)
     {
       Lisp_Object charset = Dynarr_at (data->precdyn, i);
-- 
‘As I sat looking up at the Guinness ad, I could never figure out /
How your man stayed up on the surfboard after forty pints of stout’
(C. Moore)