aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-06-22 09:25:06 -0700
committerPaul Eggert2011-06-22 09:25:06 -0700
commit9f0b1513ad9b24e2f7dec87d3afb32cd6240ccad (patch)
tree55150c011230521ce991f0c4ff36d2be4f6742f8 /src
parente92b6c884116d70e224e9cb535ed85a2b05665a5 (diff)
parent31fd4b3280acee4030efde84a0e23ae2b006ee31 (diff)
downloademacs-9f0b1513ad9b24e2f7dec87d3afb32cd6240ccad.tar.gz
emacs-9f0b1513ad9b24e2f7dec87d3afb32cd6240ccad.zip
Merge from trunk.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog207
-rw-r--r--src/alloc.c12
-rw-r--r--src/buffer.c100
-rw-r--r--src/buffer.h10
-rw-r--r--src/callproc.c15
-rw-r--r--src/category.h2
-rw-r--r--src/coding.c4
-rw-r--r--src/composite.c14
-rw-r--r--src/data.c2
-rw-r--r--src/dbusbind.c13
-rw-r--r--src/dispextern.h26
-rw-r--r--src/editfns.c22
-rw-r--r--src/emacs.c15
-rw-r--r--src/fileio.c35
-rw-r--r--src/filelock.c89
-rw-r--r--src/fns.c50
-rw-r--r--src/font.c40
-rw-r--r--src/font.h3
-rw-r--r--src/ftfont.c7
-rw-r--r--src/gtkutil.c4
-rw-r--r--src/image.c58
-rw-r--r--src/indent.c36
-rw-r--r--src/insdel.c6
-rw-r--r--src/keyboard.c4
-rw-r--r--src/lisp.h46
-rw-r--r--src/lread.c40
-rw-r--r--src/minibuf.c4
-rw-r--r--src/nsterm.h5
-rw-r--r--src/process.c2
-rw-r--r--src/termcap.c9
-rw-r--r--src/textprop.c2
-rw-r--r--src/w32term.h6
-rw-r--r--src/xdisp.c36
-rw-r--r--src/xfaces.c9
-rw-r--r--src/xfns.c13
-rw-r--r--src/xfont.c4
-rw-r--r--src/xrdb.c53
-rw-r--r--src/xselect.c2
-rw-r--r--src/xsettings.c44
-rw-r--r--src/xsmfns.c12
-rw-r--r--src/xterm.c14
-rw-r--r--src/xterm.h8
42 files changed, 630 insertions, 453 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 48625bbf285..051bcef6cf9 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,210 @@
12011-06-22 Paul Eggert <eggert@cs.ucla.edu>
2
3 Integer overflow and signedness fixes (Bug#8873).
4 A few related buffer overrun fixes, too.
5
6 * font.c (font_score): Use EMACS_INT, not int, to store XINT value.
7
8 * dispextern.h (struct face.stipple):
9 * image.c (x_bitmap_height, x_bitmap_width, x_bitmap_pixmap)
10 (x_bitmap_mask, x_allocate_bitmap_record)
11 (x_create_bitmap_from_data, x_create_bitmap_from_file)
12 (x_destroy_bitmap, x_destroy_all_bitmaps, x_create_bitmap_mask)
13 (x_create_bitmap_from_xpm_data):
14 * nsterm.h (struct ns_display_info.bitmaps_size, .bitmaps_last):
15 * w32term.h (struct w32_display_info.icon_bitmap_id, .bitmaps_size)
16 (.bitmaps_last):
17 * xfaces.c (load_pixmap):
18 * xterm.c (x_bitmap_icon, x_wm_set_icon_pixmap):
19 * xterm.h (struct x_display_info.icon_bitmap_id, .bitmaps_size)
20 (.bitmaps_last, struct x_output.icon_bitmap):
21 Use ptrdiff_t, not int, for bitmap indexes.
22 (x_allocate_bitmap_record): Check for size overflow.
23 * dispextern.h, lisp.h: Adjust to API changes elsewhere.
24
25 Use ptrdiff_t, not int, for overlay counts.
26 * buffer.h (overlays_at, sort_overlays, GET_OVERLAYS_AT):
27 * editfns.c (overlays_around, get_pos_property):
28 * textprop.c (get_char_property_and_overlay):
29 * xdisp.c (next_overlay_change, note_mouse_highlight):
30 * xfaces.c (face_at_buffer_position):
31 * buffer.c (OVERLAY_COUNT_MAX): New macro.
32 (overlays_at, overlays_in, sort_overlays, Foverlays_at)
33 (Fnext_overlay_change, Fprevious_overlay_change)
34 (mouse_face_overlay_overlaps, Foverlays_in):
35 Use ptrdiff_t, not int, for sizes.
36 (overlays_at, overlays_in): Check for size-calculation overflow.
37
38 * xterm.c (xim_initialize, same_x_server): Strlen may not fit in int.
39
40 * xsmfns.c (smc_save_yourself_CB, x_session_initialize): Avoid strlen.
41 (x_session_initialize): Do not assume string length fits in int.
42
43 * xsettings.c (apply_xft_settings): Fix potential buffer overrun.
44 This is unlikely, but can occur if DPI is outlandish.
45
46 * xsettings.c (Ffont_get_system_normal_font, Ffont_get_system_font):
47 * xselect.c (Fx_get_atom_name): Avoid need for strlen.
48
49 * xrdb.c: Don't assume strlen fits in int; avoid some strlens.
50 * xrdb.c (magic_file_p, search_magic_path):
51 Omit last arg SUFFIX; it was always 0. All callers changed.
52 (magic_file_p): Use ptrdiff_t, not int. Check for size overflow.
53
54 * xfont.c (xfont_match): Avoid need for strlen.
55
56 * xfns.c: Don't assume strlen fits in int.
57 (xic_create_fontsetname, x_window): Use ptrdiff_t, not int.
58
59 * xdisp.c (message_log_check_duplicate): Return intmax_t,
60 not unsigned long, as we prefer signed integers. All callers changed.
61 Detect integer overflow in repeat count.
62 (message_dolog): Don't assume print length fits in 39 bytes.
63 (display_mode_element): Don't assume strlen fits in int.
64
65 * termcap.c: Don't assume sizes fit in int and never overflow.
66 (struct termcap_buffer, tgetent): Use ptrdiff_t, not int, for sizes.
67 (gobble_line): Check for size-calculation overflow.
68
69 * minibuf.c (Fread_buffer):
70 * lread.c (intern, intern_c_string):
71 * image.c (xpm_scan) [HAVE_NS && !HAVE_XPM]:
72 Don't assume string length fits in int.
73
74 * keyboard.c (parse_tool_bar_item):
75 * gtkutil.c (style_changed_cb): Avoid need for strlen.
76
77 * font.c: Don't assume string length fits in int.
78 (font_parse_xlfd, font_parse_fcname, font_unparse_fcname):
79 Use ptrdiff_t, not int.
80 (font_intern_prop): Don't assume string length fits in int.
81 Don't assume integer property fits in fixnum.
82 * font.h (font_intern_prop): 2nd arg is now ptrdiff_t, not int.
83
84 * filelock.c: Fix some buffer overrun and integer overflow issues.
85 (get_boot_time): Don't assume gzip command string fits in 100 bytes.
86 Reformulate so as not to need the command string.
87 Invoke gzip -cd rather than gunzip, as it's more portable.
88 (lock_info_type, lock_file_1, lock_file):
89 Don't assume pid_t and time_t fit in unsigned long.
90 (LOCK_PID_MAX): Remove; we now use more-reliable bounds.
91 (current_lock_owner): Prefer signed type for sizes.
92 Use memcpy, not strncpy, where memcpy is what is really wanted.
93 Don't assume (via atoi) that time_t and pid_t fit in int.
94 Check for time_t and/or pid_t out of range, e.g., via a network share.
95 Don't alloca where an auto var works fine.
96
97 * fileio.c: Fix some integer overflow issues.
98 (file_name_as_directory, Fexpand_file_name, Fsubstitute_in_file_name):
99 Don't assume string length fits in int.
100 (directory_file_name): Don't assume string length fits in long.
101 (make_temp_name): Don't assume pid fits in int, or that its print
102 length is less than 20.
103
104 * data.c (Fsubr_name): Rewrite to avoid a strlen call.
105
106 * coding.c (make_subsidiaries): Don't assume string length fits in int.
107
108 * callproc.c (child_setup): Rewrite to avoid two strlen calls.
109
110 * process.c (Fformat_network_address): Use EMACS_INT, not EMACS_UINT.
111 We prefer signed integers, even for size calculations.
112
113 * emacs.c: Don't assume string length fits in 'int'.
114 (DEFINE_DUMMY_FUNCTION, sort_args): Use ptrdiff_t, not int.
115 (main): Don't invoke strlen when not needed.
116
117 * dbusbind.c (XD_ERROR): Don't arbitrarily truncate string.
118 (XD_DEBUG_MESSAGE): Don't waste a byte.
119
120 * callproc.c (getenv_internal_1, getenv_internal)
121 (Fgetenv_internal):
122 * buffer.c (init_buffer): Don't assume string length fits in 'int'.
123
124 * lread.c (invalid_syntax): Omit length argument.
125 All uses changed. This doesn't fix a bug, but it simplifies the
126 code away from its former Hollerith-constant appearance, and it's
127 one less 'int' to worry about when looking at integer-overflow issues.
128 (string_to_number): Simplify 2011-04-26 change by invoking xsignal1.
129
130 * lisp.h (DEFUN): Remove bogus use of sizeof (struct Lisp_Subr).
131 This didn't break anything, but it didn't help either.
132 It's confusing to put a bogus integer in a place where the actual
133 value does not matter.
134 (LIST_END_P): Remove unused macro and its bogus comment.
135 (make_fixnum_or_float): Remove unnecessary cast to EMACS_INT.
136
137 * lisp.h (union Lisp_Object.i): EMACS_INT, not EMACS_UINT.
138 This is for consistency with the ordinary, non-USE_LISP_UNION_TYPE,
139 implementation.
140 (struct Lisp_Bool_Vector.size): EMACS_INT, not EMACS_UINT.
141 We prefer signed types, and the value cannot exceed the EMACS_INT
142 range anyway (because otherwise the length would not be representable).
143 (XSET) [USE_LISP_UNION_TYPE]: Use uintptr_t and intptr_t,
144 not EMACS_UINT and EMACS_INT, when converting pointer to integer.
145 This avoids a GCC warning when WIDE_EMACS_INT.
146
147 * indent.c (sane_tab_width): New function.
148 (current_column, scan_for_column, Findent_to, position_indentation)
149 (compute_motion): Use it. This is just for clarity.
150 (Fcompute_motion): Don't assume hscroll and tab offset fit in int.
151
152 * image.c (xbm_image_p): Don't assume stated width, height fit in int.
153
154 * lisp.h (lint_assume): New macro.
155 * composite.c (composition_gstring_put_cache):
156 * ftfont.c (ftfont_shape_by_flt): Use it to pacify GCC 4.6.0.
157
158 * editfns.c, insdel.c:
159 Omit unnecessary forward decls, to simplify future changes.
160
161 * ftfont.c (ftfont_shape_by_flt): Use signed integers for lengths.
162
163 * font.c (Ffont_shape_gstring): Don't assume glyph len fits in 'int'.
164
165 * fns.c (Ffillarray): Don't assume bool vector size fits in 'int'.
166 Use much-faster test for byte-length change.
167 Don't assume string byte-length fits in 'int'.
168 Check that character arg fits in 'int'.
169 (mapcar1): Declare byte as byte, for clarity.
170
171 * alloc.c (Fmake_bool_vector): Avoid unnecessary multiplication.
172
173 * fns.c (concat): Catch string overflow earlier.
174 Do not rely on integer wraparound.
175
176 * dispextern.h (struct it.overlay_strings_charpos)
177 (struct it.selective): Now EMACS_INT, not int.
178 * xdisp.c (forward_to_next_line_start)
179 (back_to_previous_visible_line_start)
180 (reseat_at_next_visible_line_start, next_element_from_buffer):
181 Don't arbitrarily truncate the value of 'selective' to int.
182
183 * xdisp.c (init_iterator): Use XINT, not XFASTINT; it might be < 0.
184
185 * composite.c: Don't truncate sizes to 'int'.
186 (composition_gstring_p, composition_reseat_it)
187 (composition_adjust_point): Use EMACS_INT, not int.
188 (get_composition_id, composition_gstring_put_cache): Use EMACS_INT,
189 not EMACS_UINT, for indexes.
190
191 * category.h (CATEGORY_SET_P): Remove unnecessary cast to EMACS_INT.
192
193 * buffer.c: Include <verify.h>.
194 (struct sortvec.priority, struct sortstr.priority):
195 Now EMACS_INT, not int.
196 (compare_overlays, cmp_for_strings): Avoid subtraction overflow.
197 (struct sortstr.size, record_overlay_string)
198 (struct sortstrlist.size, struct sortlist.used):
199 Don't truncate size to int.
200 (record_overlay_string): Check for size-calculation overflow.
201 (init_buffer_once): Check at compile-time, not run-time.
202
2032011-06-22 Jim Meyering <meyering@redhat.com>
204
205 don't leak an XBM-image-sized buffer
206 * image.c (xbm_load): Free the image buffer after using it.
207
12011-06-21 Paul Eggert <eggert@cs.ucla.edu> 2082011-06-21 Paul Eggert <eggert@cs.ucla.edu>
2 209
3 Port to Sun C. 210 Port to Sun C.
diff --git a/src/alloc.c b/src/alloc.c
index 00d330c1b6a..69623d103c3 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -2257,12 +2257,14 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2257 p = XBOOL_VECTOR (val); 2257 p = XBOOL_VECTOR (val);
2258 p->size = XFASTINT (length); 2258 p->size = XFASTINT (length);
2259 2259
2260 memset (p->data, NILP (init) ? 0 : -1, length_in_chars); 2260 if (length_in_chars)
2261 {
2262 memset (p->data, ! NILP (init) ? -1 : 0, length_in_chars);
2261 2263
2262 /* Clear the extraneous bits in the last byte. */ 2264 /* Clear any extraneous bits in the last byte. */
2263 if (XINT (length) != length_in_chars * BOOL_VECTOR_BITS_PER_CHAR) 2265 p->data[length_in_chars - 1]
2264 p->data[length_in_chars - 1] 2266 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1;
2265 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1; 2267 }
2266 2268
2267 return val; 2269 return val;
2268} 2270}
diff --git a/src/buffer.c b/src/buffer.c
index d7adf63c98b..238923a2ba0 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -27,6 +27,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
27#include <setjmp.h> 27#include <setjmp.h>
28#include <unistd.h> 28#include <unistd.h>
29 29
30#include <verify.h>
31
30#include "lisp.h" 32#include "lisp.h"
31#include "intervals.h" 33#include "intervals.h"
32#include "window.h" 34#include "window.h"
@@ -92,6 +94,11 @@ static Lisp_Object Vbuffer_local_symbols;
92#define PER_BUFFER_SYMBOL(OFFSET) \ 94#define PER_BUFFER_SYMBOL(OFFSET) \
93 (*(Lisp_Object *)((OFFSET) + (char *) &buffer_local_symbols)) 95 (*(Lisp_Object *)((OFFSET) + (char *) &buffer_local_symbols))
94 96
97/* Maximum length of an overlay vector. */
98#define OVERLAY_COUNT_MAX \
99 ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, \
100 min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object)))
101
95/* Flags indicating which built-in buffer-local variables 102/* Flags indicating which built-in buffer-local variables
96 are permanent locals. */ 103 are permanent locals. */
97static char buffer_permanent_local_flags[MAX_PER_BUFFER_VARS]; 104static char buffer_permanent_local_flags[MAX_PER_BUFFER_VARS];
@@ -2516,14 +2523,15 @@ swap_out_buffer_local_variables (struct buffer *b)
2516 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the 2523 *NEXT_PTR is guaranteed to be not equal to POS, unless it is the
2517 default (BEGV or ZV). */ 2524 default (BEGV or ZV). */
2518 2525
2519int 2526ptrdiff_t
2520overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, int *len_ptr, 2527overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
2528 ptrdiff_t *len_ptr,
2521 EMACS_INT *next_ptr, EMACS_INT *prev_ptr, int change_req) 2529 EMACS_INT *next_ptr, EMACS_INT *prev_ptr, int change_req)
2522{ 2530{
2523 Lisp_Object overlay, start, end; 2531 Lisp_Object overlay, start, end;
2524 struct Lisp_Overlay *tail; 2532 struct Lisp_Overlay *tail;
2525 int idx = 0; 2533 ptrdiff_t idx = 0;
2526 int len = *len_ptr; 2534 ptrdiff_t len = *len_ptr;
2527 Lisp_Object *vec = *vec_ptr; 2535 Lisp_Object *vec = *vec_ptr;
2528 EMACS_INT next = ZV; 2536 EMACS_INT next = ZV;
2529 EMACS_INT prev = BEGV; 2537 EMACS_INT prev = BEGV;
@@ -2559,10 +2567,10 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, int *len_ptr,
2559 Either make it bigger, or don't store any more in it. */ 2567 Either make it bigger, or don't store any more in it. */
2560 if (extend) 2568 if (extend)
2561 { 2569 {
2570 if ((OVERLAY_COUNT_MAX - 4) / 2 < len)
2571 memory_full (SIZE_MAX);
2562 /* Make it work with an initial len == 0. */ 2572 /* Make it work with an initial len == 0. */
2563 len *= 2; 2573 len = len * 2 + 4;
2564 if (len == 0)
2565 len = 4;
2566 *len_ptr = len; 2574 *len_ptr = len;
2567 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); 2575 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
2568 *vec_ptr = vec; 2576 *vec_ptr = vec;
@@ -2602,10 +2610,10 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, int *len_ptr,
2602 { 2610 {
2603 if (extend) 2611 if (extend)
2604 { 2612 {
2613 if ((OVERLAY_COUNT_MAX - 4) / 2 < len)
2614 memory_full (SIZE_MAX);
2605 /* Make it work with an initial len == 0. */ 2615 /* Make it work with an initial len == 0. */
2606 len *= 2; 2616 len = len * 2 + 4;
2607 if (len == 0)
2608 len = 4;
2609 *len_ptr = len; 2617 *len_ptr = len;
2610 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); 2618 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
2611 *vec_ptr = vec; 2619 *vec_ptr = vec;
@@ -2655,15 +2663,15 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, int *len_ptr,
2655 and we store only as many overlays as will fit. 2663 and we store only as many overlays as will fit.
2656 But we still return the total number of overlays. */ 2664 But we still return the total number of overlays. */
2657 2665
2658static int 2666static ptrdiff_t
2659overlays_in (EMACS_INT beg, EMACS_INT end, int extend, 2667overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2660 Lisp_Object **vec_ptr, int *len_ptr, 2668 Lisp_Object **vec_ptr, ptrdiff_t *len_ptr,
2661 EMACS_INT *next_ptr, EMACS_INT *prev_ptr) 2669 EMACS_INT *next_ptr, EMACS_INT *prev_ptr)
2662{ 2670{
2663 Lisp_Object overlay, ostart, oend; 2671 Lisp_Object overlay, ostart, oend;
2664 struct Lisp_Overlay *tail; 2672 struct Lisp_Overlay *tail;
2665 int idx = 0; 2673 ptrdiff_t idx = 0;
2666 int len = *len_ptr; 2674 ptrdiff_t len = *len_ptr;
2667 Lisp_Object *vec = *vec_ptr; 2675 Lisp_Object *vec = *vec_ptr;
2668 EMACS_INT next = ZV; 2676 EMACS_INT next = ZV;
2669 EMACS_INT prev = BEGV; 2677 EMACS_INT prev = BEGV;
@@ -2699,10 +2707,10 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2699 Either make it bigger, or don't store any more in it. */ 2707 Either make it bigger, or don't store any more in it. */
2700 if (extend) 2708 if (extend)
2701 { 2709 {
2710 if ((OVERLAY_COUNT_MAX - 4) / 2 < len)
2711 memory_full (SIZE_MAX);
2702 /* Make it work with an initial len == 0. */ 2712 /* Make it work with an initial len == 0. */
2703 len *= 2; 2713 len = len * 2 + 4;
2704 if (len == 0)
2705 len = 4;
2706 *len_ptr = len; 2714 *len_ptr = len;
2707 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); 2715 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
2708 *vec_ptr = vec; 2716 *vec_ptr = vec;
@@ -2747,10 +2755,10 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend,
2747 { 2755 {
2748 if (extend) 2756 if (extend)
2749 { 2757 {
2758 if ((OVERLAY_COUNT_MAX - 4) / 2 < len)
2759 memory_full (SIZE_MAX);
2750 /* Make it work with an initial len == 0. */ 2760 /* Make it work with an initial len == 0. */
2751 len *= 2; 2761 len = len * 2 + 4;
2752 if (len == 0)
2753 len = 4;
2754 *len_ptr = len; 2762 *len_ptr = len;
2755 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object)); 2763 vec = (Lisp_Object *) xrealloc (vec, len * sizeof (Lisp_Object));
2756 *vec_ptr = vec; 2764 *vec_ptr = vec;
@@ -2783,7 +2791,7 @@ mouse_face_overlay_overlaps (Lisp_Object overlay)
2783{ 2791{
2784 EMACS_INT start = OVERLAY_POSITION (OVERLAY_START (overlay)); 2792 EMACS_INT start = OVERLAY_POSITION (OVERLAY_START (overlay));
2785 EMACS_INT end = OVERLAY_POSITION (OVERLAY_END (overlay)); 2793 EMACS_INT end = OVERLAY_POSITION (OVERLAY_END (overlay));
2786 int n, i, size; 2794 ptrdiff_t n, i, size;
2787 Lisp_Object *v, tem; 2795 Lisp_Object *v, tem;
2788 2796
2789 size = 10; 2797 size = 10;
@@ -2849,7 +2857,7 @@ struct sortvec
2849{ 2857{
2850 Lisp_Object overlay; 2858 Lisp_Object overlay;
2851 EMACS_INT beg, end; 2859 EMACS_INT beg, end;
2852 int priority; 2860 EMACS_INT priority;
2853}; 2861};
2854 2862
2855static int 2863static int
@@ -2858,21 +2866,21 @@ compare_overlays (const void *v1, const void *v2)
2858 const struct sortvec *s1 = (const struct sortvec *) v1; 2866 const struct sortvec *s1 = (const struct sortvec *) v1;
2859 const struct sortvec *s2 = (const struct sortvec *) v2; 2867 const struct sortvec *s2 = (const struct sortvec *) v2;
2860 if (s1->priority != s2->priority) 2868 if (s1->priority != s2->priority)
2861 return s1->priority - s2->priority; 2869 return s1->priority < s2->priority ? -1 : 1;
2862 if (s1->beg != s2->beg) 2870 if (s1->beg != s2->beg)
2863 return s1->beg - s2->beg; 2871 return s1->beg < s2->beg ? -1 : 1;
2864 if (s1->end != s2->end) 2872 if (s1->end != s2->end)
2865 return s2->end - s1->end; 2873 return s2->end < s1->end ? -1 : 1;
2866 return 0; 2874 return 0;
2867} 2875}
2868 2876
2869/* Sort an array of overlays by priority. The array is modified in place. 2877/* Sort an array of overlays by priority. The array is modified in place.
2870 The return value is the new size; this may be smaller than the original 2878 The return value is the new size; this may be smaller than the original
2871 size if some of the overlays were invalid or were window-specific. */ 2879 size if some of the overlays were invalid or were window-specific. */
2872int 2880ptrdiff_t
2873sort_overlays (Lisp_Object *overlay_vec, int noverlays, struct window *w) 2881sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w)
2874{ 2882{
2875 int i, j; 2883 ptrdiff_t i, j;
2876 struct sortvec *sortvec; 2884 struct sortvec *sortvec;
2877 sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec)); 2885 sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec));
2878 2886
@@ -2926,15 +2934,15 @@ sort_overlays (Lisp_Object *overlay_vec, int noverlays, struct window *w)
2926struct sortstr 2934struct sortstr
2927{ 2935{
2928 Lisp_Object string, string2; 2936 Lisp_Object string, string2;
2929 int size; 2937 ptrdiff_t size;
2930 int priority; 2938 EMACS_INT priority;
2931}; 2939};
2932 2940
2933struct sortstrlist 2941struct sortstrlist
2934{ 2942{
2935 struct sortstr *buf; /* An array that expands as needed; never freed. */ 2943 struct sortstr *buf; /* An array that expands as needed; never freed. */
2936 int size; /* Allocated length of that array. */ 2944 ptrdiff_t size; /* Allocated length of that array. */
2937 int used; /* How much of the array is currently in use. */ 2945 ptrdiff_t used; /* How much of the array is currently in use. */
2938 EMACS_INT bytes; /* Total length of the strings in buf. */ 2946 EMACS_INT bytes; /* Total length of the strings in buf. */
2939}; 2947};
2940 2948
@@ -2955,20 +2963,24 @@ cmp_for_strings (const void *as1, const void *as2)
2955 struct sortstr *s1 = (struct sortstr *)as1; 2963 struct sortstr *s1 = (struct sortstr *)as1;
2956 struct sortstr *s2 = (struct sortstr *)as2; 2964 struct sortstr *s2 = (struct sortstr *)as2;
2957 if (s1->size != s2->size) 2965 if (s1->size != s2->size)
2958 return s2->size - s1->size; 2966 return s2->size < s1->size ? -1 : 1;
2959 if (s1->priority != s2->priority) 2967 if (s1->priority != s2->priority)
2960 return s1->priority - s2->priority; 2968 return s1->priority < s2->priority ? -1 : 1;
2961 return 0; 2969 return 0;
2962} 2970}
2963 2971
2964static void 2972static void
2965record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, Lisp_Object str2, Lisp_Object pri, int size) 2973record_overlay_string (struct sortstrlist *ssl, Lisp_Object str,
2974 Lisp_Object str2, Lisp_Object pri, ptrdiff_t size)
2966{ 2975{
2967 EMACS_INT nbytes; 2976 EMACS_INT nbytes;
2968 2977
2969 if (ssl->used == ssl->size) 2978 if (ssl->used == ssl->size)
2970 { 2979 {
2971 if (ssl->buf) 2980 if (min (PTRDIFF_MAX, SIZE_MAX) / (sizeof (struct sortstr) * 2)
2981 < ssl->size)
2982 memory_full (SIZE_MAX);
2983 else if (0 < ssl->size)
2972 ssl->size *= 2; 2984 ssl->size *= 2;
2973 else 2985 else
2974 ssl->size = 5; 2986 ssl->size = 5;
@@ -3874,9 +3886,8 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
3874 doc: /* Return a list of the overlays that contain the character at POS. */) 3886 doc: /* Return a list of the overlays that contain the character at POS. */)
3875 (Lisp_Object pos) 3887 (Lisp_Object pos)
3876{ 3888{
3877 int noverlays; 3889 ptrdiff_t len, noverlays;
3878 Lisp_Object *overlay_vec; 3890 Lisp_Object *overlay_vec;
3879 int len;
3880 Lisp_Object result; 3891 Lisp_Object result;
3881 3892
3882 CHECK_NUMBER_COERCE_MARKER (pos); 3893 CHECK_NUMBER_COERCE_MARKER (pos);
@@ -3906,9 +3917,8 @@ between BEG and END, or at END provided END denotes the position at the
3906end of the buffer. */) 3917end of the buffer. */)
3907 (Lisp_Object beg, Lisp_Object end) 3918 (Lisp_Object beg, Lisp_Object end)
3908{ 3919{
3909 int noverlays; 3920 ptrdiff_t len, noverlays;
3910 Lisp_Object *overlay_vec; 3921 Lisp_Object *overlay_vec;
3911 int len;
3912 Lisp_Object result; 3922 Lisp_Object result;
3913 3923
3914 CHECK_NUMBER_COERCE_MARKER (beg); 3924 CHECK_NUMBER_COERCE_MARKER (beg);
@@ -3936,11 +3946,9 @@ If there are no overlay boundaries from POS to (point-max),
3936the value is (point-max). */) 3946the value is (point-max). */)
3937 (Lisp_Object pos) 3947 (Lisp_Object pos)
3938{ 3948{
3939 int noverlays; 3949 ptrdiff_t i, len, noverlays;
3940 EMACS_INT endpos; 3950 EMACS_INT endpos;
3941 Lisp_Object *overlay_vec; 3951 Lisp_Object *overlay_vec;
3942 int len;
3943 int i;
3944 3952
3945 CHECK_NUMBER_COERCE_MARKER (pos); 3953 CHECK_NUMBER_COERCE_MARKER (pos);
3946 3954
@@ -3979,7 +3987,7 @@ the value is (point-min). */)
3979{ 3987{
3980 EMACS_INT prevpos; 3988 EMACS_INT prevpos;
3981 Lisp_Object *overlay_vec; 3989 Lisp_Object *overlay_vec;
3982 int len; 3990 ptrdiff_t len;
3983 3991
3984 CHECK_NUMBER_COERCE_MARKER (pos); 3992 CHECK_NUMBER_COERCE_MARKER (pos);
3985 3993
@@ -4971,7 +4979,7 @@ init_buffer_once (void)
4971 The local flag bits are in the local_var_flags slot of the buffer. */ 4979 The local flag bits are in the local_var_flags slot of the buffer. */
4972 4980
4973 /* Nothing can work if this isn't true */ 4981 /* Nothing can work if this isn't true */
4974 if (sizeof (EMACS_INT) != sizeof (Lisp_Object)) abort (); 4982 { verify (sizeof (EMACS_INT) == sizeof (Lisp_Object)); }
4975 4983
4976 /* 0 means not a lisp var, -1 means always local, else mask */ 4984 /* 0 means not a lisp var, -1 means always local, else mask */
4977 memset (&buffer_local_flags, 0, sizeof buffer_local_flags); 4985 memset (&buffer_local_flags, 0, sizeof buffer_local_flags);
@@ -5077,7 +5085,7 @@ init_buffer (void)
5077{ 5085{
5078 char *pwd; 5086 char *pwd;
5079 Lisp_Object temp; 5087 Lisp_Object temp;
5080 int len; 5088 ptrdiff_t len;
5081 5089
5082#ifdef USE_MMAP_FOR_BUFFERS 5090#ifdef USE_MMAP_FOR_BUFFERS
5083 { 5091 {
diff --git a/src/buffer.h b/src/buffer.h
index a13351b5ea6..4643e0d9d0e 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -887,10 +887,10 @@ extern struct buffer buffer_local_symbols;
887extern void delete_all_overlays (struct buffer *); 887extern void delete_all_overlays (struct buffer *);
888extern void reset_buffer (struct buffer *); 888extern void reset_buffer (struct buffer *);
889extern void evaporate_overlays (EMACS_INT); 889extern void evaporate_overlays (EMACS_INT);
890extern int overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, 890extern ptrdiff_t overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr,
891 int *len_ptr, EMACS_INT *next_ptr, 891 ptrdiff_t *len_ptr, EMACS_INT *next_ptr,
892 EMACS_INT *prev_ptr, int change_req); 892 EMACS_INT *prev_ptr, int change_req);
893extern int sort_overlays (Lisp_Object *, int, struct window *); 893extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *);
894extern void recenter_overlay_lists (struct buffer *, EMACS_INT); 894extern void recenter_overlay_lists (struct buffer *, EMACS_INT);
895extern EMACS_INT overlay_strings (EMACS_INT, struct window *, unsigned char **); 895extern EMACS_INT overlay_strings (EMACS_INT, struct window *, unsigned char **);
896extern void validate_region (Lisp_Object *, Lisp_Object *); 896extern void validate_region (Lisp_Object *, Lisp_Object *);
@@ -908,7 +908,7 @@ extern void mmap_set_vars (int);
908 908
909#define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \ 909#define GET_OVERLAYS_AT(posn, overlays, noverlays, nextp, chrq) \
910 do { \ 910 do { \
911 int maxlen = 40; \ 911 ptrdiff_t maxlen = 40; \
912 overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \ 912 overlays = (Lisp_Object *) alloca (maxlen * sizeof (Lisp_Object)); \
913 noverlays = overlays_at (posn, 0, &overlays, &maxlen, \ 913 noverlays = overlays_at (posn, 0, &overlays, &maxlen, \
914 nextp, NULL, chrq); \ 914 nextp, NULL, chrq); \
diff --git a/src/callproc.c b/src/callproc.c
index d6bad2a44e7..b339f343f62 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1230,8 +1230,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L
1230 1230
1231 if (STRINGP (display)) 1231 if (STRINGP (display))
1232 { 1232 {
1233 int vlen = strlen ("DISPLAY=") + strlen (SSDATA (display)) + 1; 1233 char *vdata = (char *) alloca (sizeof "DISPLAY=" + SBYTES (display));
1234 char *vdata = (char *) alloca (vlen);
1235 strcpy (vdata, "DISPLAY="); 1234 strcpy (vdata, "DISPLAY=");
1236 strcat (vdata, SSDATA (display)); 1235 strcat (vdata, SSDATA (display));
1237 new_env = add_env (env, new_env, vdata); 1236 new_env = add_env (env, new_env, vdata);
@@ -1378,8 +1377,8 @@ relocate_fd (int fd, int minfd)
1378#endif /* not WINDOWSNT */ 1377#endif /* not WINDOWSNT */
1379 1378
1380static int 1379static int
1381getenv_internal_1 (const char *var, int varlen, char **value, int *valuelen, 1380getenv_internal_1 (const char *var, ptrdiff_t varlen, char **value,
1382 Lisp_Object env) 1381 ptrdiff_t *valuelen, Lisp_Object env)
1383{ 1382{
1384 for (; CONSP (env); env = XCDR (env)) 1383 for (; CONSP (env); env = XCDR (env))
1385 { 1384 {
@@ -1413,8 +1412,8 @@ getenv_internal_1 (const char *var, int varlen, char **value, int *valuelen,
1413} 1412}
1414 1413
1415static int 1414static int
1416getenv_internal (const char *var, int varlen, char **value, int *valuelen, 1415getenv_internal (const char *var, ptrdiff_t varlen, char **value,
1417 Lisp_Object frame) 1416 ptrdiff_t *valuelen, Lisp_Object frame)
1418{ 1417{
1419 /* Try to find VAR in Vprocess_environment first. */ 1418 /* Try to find VAR in Vprocess_environment first. */
1420 if (getenv_internal_1 (var, varlen, value, valuelen, 1419 if (getenv_internal_1 (var, varlen, value, valuelen,
@@ -1454,7 +1453,7 @@ If optional parameter ENV is a list, then search this list instead of
1454 (Lisp_Object variable, Lisp_Object env) 1453 (Lisp_Object variable, Lisp_Object env)
1455{ 1454{
1456 char *value; 1455 char *value;
1457 int valuelen; 1456 ptrdiff_t valuelen;
1458 1457
1459 CHECK_STRING (variable); 1458 CHECK_STRING (variable);
1460 if (CONSP (env)) 1459 if (CONSP (env))
@@ -1478,7 +1477,7 @@ char *
1478egetenv (const char *var) 1477egetenv (const char *var)
1479{ 1478{
1480 char *value; 1479 char *value;
1481 int valuelen; 1480 ptrdiff_t valuelen;
1482 1481
1483 if (getenv_internal (var, strlen (var), &value, &valuelen, Qnil)) 1482 if (getenv_internal (var, strlen (var), &value, &valuelen, Qnil))
1484 return value; 1483 return value;
diff --git a/src/category.h b/src/category.h
index eacd89ce2cb..737198cc964 100644
--- a/src/category.h
+++ b/src/category.h
@@ -62,7 +62,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
62#define XCATEGORY_SET XBOOL_VECTOR 62#define XCATEGORY_SET XBOOL_VECTOR
63 63
64#define CATEGORY_SET_P(x) \ 64#define CATEGORY_SET_P(x) \
65 (BOOL_VECTOR_P ((x)) && (EMACS_INT) (XBOOL_VECTOR ((x))->size) == 128) 65 (BOOL_VECTOR_P (x) && XBOOL_VECTOR (x)->size == 128)
66 66
67/* Return a new empty category set. */ 67/* Return a new empty category set. */
68#define MAKE_CATEGORY_SET (Fmake_bool_vector (make_number (128), Qnil)) 68#define MAKE_CATEGORY_SET (Fmake_bool_vector (make_number (128), Qnil))
diff --git a/src/coding.c b/src/coding.c
index 04985ab3c74..9939774ea82 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -9442,7 +9442,7 @@ static Lisp_Object
9442make_subsidiaries (Lisp_Object base) 9442make_subsidiaries (Lisp_Object base)
9443{ 9443{
9444 Lisp_Object subsidiaries; 9444 Lisp_Object subsidiaries;
9445 int base_name_len = SBYTES (SYMBOL_NAME (base)); 9445 ptrdiff_t base_name_len = SBYTES (SYMBOL_NAME (base));
9446 char *buf = (char *) alloca (base_name_len + 6); 9446 char *buf = (char *) alloca (base_name_len + 6);
9447 int i; 9447 int i;
9448 9448
@@ -9450,7 +9450,7 @@ make_subsidiaries (Lisp_Object base)
9450 subsidiaries = Fmake_vector (make_number (3), Qnil); 9450 subsidiaries = Fmake_vector (make_number (3), Qnil);
9451 for (i = 0; i < 3; i++) 9451 for (i = 0; i < 3; i++)
9452 { 9452 {
9453 memcpy (buf + base_name_len, suffixes[i], strlen (suffixes[i]) + 1); 9453 strcpy (buf + base_name_len, suffixes[i]);
9454 ASET (subsidiaries, i, intern (buf)); 9454 ASET (subsidiaries, i, intern (buf));
9455 } 9455 }
9456 return subsidiaries; 9456 return subsidiaries;
diff --git a/src/composite.c b/src/composite.c
index 6a4fe803804..796c5a58de6 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -285,7 +285,7 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
285 && VECTORP (AREF (components, 0))) 285 && VECTORP (AREF (components, 0)))
286 { 286 {
287 /* COMPONENTS is a glyph-string. */ 287 /* COMPONENTS is a glyph-string. */
288 EMACS_UINT len = ASIZE (key); 288 EMACS_INT len = ASIZE (key);
289 289
290 for (i = 1; i < len; i++) 290 for (i = 1; i < len; i++)
291 if (! VECTORP (AREF (key, i))) 291 if (! VECTORP (AREF (key, i)))
@@ -293,7 +293,7 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
293 } 293 }
294 else if (VECTORP (components) || CONSP (components)) 294 else if (VECTORP (components) || CONSP (components))
295 { 295 {
296 EMACS_UINT len = ASIZE (key); 296 EMACS_INT len = ASIZE (key);
297 297
298 /* The number of elements should be odd. */ 298 /* The number of elements should be odd. */
299 if ((len % 2) == 0) 299 if ((len % 2) == 0)
@@ -673,13 +673,14 @@ composition_gstring_put_cache (Lisp_Object gstring, EMACS_INT len)
673 hash = h->hashfn (h, header); 673 hash = h->hashfn (h, header);
674 if (len < 0) 674 if (len < 0)
675 { 675 {
676 EMACS_UINT j, glyph_len = LGSTRING_GLYPH_LEN (gstring); 676 EMACS_INT j, glyph_len = LGSTRING_GLYPH_LEN (gstring);
677 for (j = 0; j < glyph_len; j++) 677 for (j = 0; j < glyph_len; j++)
678 if (NILP (LGSTRING_GLYPH (gstring, j))) 678 if (NILP (LGSTRING_GLYPH (gstring, j)))
679 break; 679 break;
680 len = j; 680 len = j;
681 } 681 }
682 682
683 lint_assume (len <= TYPE_MAXIMUM (EMACS_INT) - 2);
683 copy = Fmake_vector (make_number (len + 2), Qnil); 684 copy = Fmake_vector (make_number (len + 2), Qnil);
684 LGSTRING_SET_HEADER (copy, Fcopy_sequence (header)); 685 LGSTRING_SET_HEADER (copy, Fcopy_sequence (header));
685 for (i = 0; i < len; i++) 686 for (i = 0; i < len; i++)
@@ -705,7 +706,7 @@ int
705composition_gstring_p (Lisp_Object gstring) 706composition_gstring_p (Lisp_Object gstring)
706{ 707{
707 Lisp_Object header; 708 Lisp_Object header;
708 int i; 709 EMACS_INT i;
709 710
710 if (! VECTORP (gstring) || ASIZE (gstring) < 2) 711 if (! VECTORP (gstring) || ASIZE (gstring) < 2)
711 return 0; 712 return 0;
@@ -1252,7 +1253,7 @@ composition_reseat_it (struct composition_it *cmp_it, EMACS_INT charpos, EMACS_I
1252 { 1253 {
1253 Lisp_Object lgstring = Qnil; 1254 Lisp_Object lgstring = Qnil;
1254 Lisp_Object val, elt; 1255 Lisp_Object val, elt;
1255 int i; 1256 EMACS_INT i;
1256 1257
1257 val = CHAR_TABLE_REF (Vcomposition_function_table, cmp_it->ch); 1258 val = CHAR_TABLE_REF (Vcomposition_function_table, cmp_it->ch);
1258 for (i = 0; i < cmp_it->rule_idx; i++, val = XCDR (val)); 1259 for (i = 0; i < cmp_it->rule_idx; i++, val = XCDR (val));
@@ -1684,9 +1685,8 @@ find_automatic_composition (EMACS_INT pos, EMACS_INT limit,
1684EMACS_INT 1685EMACS_INT
1685composition_adjust_point (EMACS_INT last_pt, EMACS_INT new_pt) 1686composition_adjust_point (EMACS_INT last_pt, EMACS_INT new_pt)
1686{ 1687{
1687 EMACS_INT beg, end; 1688 EMACS_INT i, beg, end;
1688 Lisp_Object val; 1689 Lisp_Object val;
1689 int i;
1690 1690
1691 if (new_pt == BEGV || new_pt == ZV) 1691 if (new_pt == BEGV || new_pt == ZV)
1692 return new_pt; 1692 return new_pt;
diff --git a/src/data.c b/src/data.c
index cf01d38036d..6b4ea32ac9e 100644
--- a/src/data.c
+++ b/src/data.c
@@ -703,7 +703,7 @@ SUBR must be a built-in function. */)
703 const char *name; 703 const char *name;
704 CHECK_SUBR (subr); 704 CHECK_SUBR (subr);
705 name = XSUBR (subr)->symbol_name; 705 name = XSUBR (subr)->symbol_name;
706 return make_string (name, strlen (name)); 706 return build_string (name);
707} 707}
708 708
709DEFUN ("interactive-form", Finteractive_form, Sinteractive_form, 1, 1, 0, 709DEFUN ("interactive-form", Finteractive_form, Sinteractive_form, 1, 1, 0,
diff --git a/src/dbusbind.c b/src/dbusbind.c
index f662d5b38a2..302b93146fd 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -111,13 +111,12 @@ static int xd_in_read_queued_messages = 0;
111/* Raise a Lisp error from a D-Bus ERROR. */ 111/* Raise a Lisp error from a D-Bus ERROR. */
112#define XD_ERROR(error) \ 112#define XD_ERROR(error) \
113 do { \ 113 do { \
114 char s[1024]; \
115 strncpy (s, error.message, 1023); \
116 dbus_error_free (&error); \
117 /* Remove the trailing newline. */ \ 114 /* Remove the trailing newline. */ \
118 if (strchr (s, '\n') != NULL) \ 115 char const *mess = error.message; \
119 s[strlen (s) - 1] = '\0'; \ 116 char const *nl = strchr (mess, '\n'); \
120 XD_SIGNAL1 (build_string (s)); \ 117 Lisp_Object err = make_string (mess, nl ? nl - mess : strlen (mess)); \
118 dbus_error_free (&error); \
119 XD_SIGNAL1 (err); \
121 } while (0) 120 } while (0)
122 121
123/* Macros for debugging. In order to enable them, build with 122/* Macros for debugging. In order to enable them, build with
@@ -126,7 +125,7 @@ static int xd_in_read_queued_messages = 0;
126#define XD_DEBUG_MESSAGE(...) \ 125#define XD_DEBUG_MESSAGE(...) \
127 do { \ 126 do { \
128 char s[1024]; \ 127 char s[1024]; \
129 snprintf (s, 1023, __VA_ARGS__); \ 128 snprintf (s, sizeof s, __VA_ARGS__); \
130 printf ("%s: %s\n", __func__, s); \ 129 printf ("%s: %s\n", __func__, s); \
131 message ("%s: %s", __func__, s); \ 130 message ("%s: %s", __func__, s); \
132 } while (0) 131 } while (0)
diff --git a/src/dispextern.h b/src/dispextern.h
index 0ededf33ac6..02f1e5314aa 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -1532,12 +1532,12 @@ struct face
1532 1532
1533 /* Background stipple or bitmap used for this face. This is 1533 /* Background stipple or bitmap used for this face. This is
1534 an id as returned from load_pixmap. */ 1534 an id as returned from load_pixmap. */
1535 int stipple; 1535 ptrdiff_t stipple;
1536 1536
1537#else /* not HAVE_WINDOW_SYSTEM */ 1537#else /* not HAVE_WINDOW_SYSTEM */
1538 1538
1539 /* Dummy. */ 1539 /* Dummy. */
1540 int stipple; 1540 ptrdiff_t stipple;
1541 1541
1542#endif /* not HAVE_WINDOW_SYSTEM */ 1542#endif /* not HAVE_WINDOW_SYSTEM */
1543 1543
@@ -2183,7 +2183,7 @@ struct it
2183 be set at the same time as n_overlay_strings. It is needed 2183 be set at the same time as n_overlay_strings. It is needed
2184 because we show before-strings at the start of invisible text; 2184 because we show before-strings at the start of invisible text;
2185 see handle_invisible_prop in xdisp.c. */ 2185 see handle_invisible_prop in xdisp.c. */
2186 int overlay_strings_charpos; 2186 EMACS_INT overlay_strings_charpos;
2187 2187
2188 /* Vector of overlays to process. Overlay strings are processed 2188 /* Vector of overlays to process. Overlay strings are processed
2189 OVERLAY_STRING_CHUNK_SIZE at a time. */ 2189 OVERLAY_STRING_CHUNK_SIZE at a time. */
@@ -2259,7 +2259,7 @@ struct it
2259 2259
2260 /* -1 means selective display hides everything between a \r and the 2260 /* -1 means selective display hides everything between a \r and the
2261 next newline; > 0 means hide lines indented more than that value. */ 2261 next newline; > 0 means hide lines indented more than that value. */
2262 int selective; 2262 EMACS_INT selective;
2263 2263
2264 /* An enumeration describing what the next display element is 2264 /* An enumeration describing what the next display element is
2265 after a call to get_next_display_element. */ 2265 after a call to get_next_display_element. */
@@ -3082,21 +3082,21 @@ void w32_reset_fringes (void);
3082 3082
3083#ifdef HAVE_WINDOW_SYSTEM 3083#ifdef HAVE_WINDOW_SYSTEM
3084 3084
3085extern int x_bitmap_height (struct frame *, int); 3085extern int x_bitmap_height (struct frame *, ptrdiff_t);
3086extern int x_bitmap_width (struct frame *, int); 3086extern int x_bitmap_width (struct frame *, ptrdiff_t);
3087extern int x_bitmap_pixmap (struct frame *, int); 3087extern int x_bitmap_pixmap (struct frame *, ptrdiff_t);
3088extern void x_reference_bitmap (struct frame *, int); 3088extern void x_reference_bitmap (struct frame *, int);
3089extern int x_create_bitmap_from_data (struct frame *, char *, 3089extern ptrdiff_t x_create_bitmap_from_data (struct frame *, char *,
3090 unsigned int, unsigned int); 3090 unsigned int, unsigned int);
3091extern int x_create_bitmap_from_file (struct frame *, Lisp_Object); 3091extern ptrdiff_t x_create_bitmap_from_file (struct frame *, Lisp_Object);
3092#if defined HAVE_XPM && defined HAVE_X_WINDOWS && !defined USE_GTK 3092#if defined HAVE_XPM && defined HAVE_X_WINDOWS && !defined USE_GTK
3093extern int x_create_bitmap_from_xpm_data (struct frame *f, const char **bits); 3093extern ptrdiff_t x_create_bitmap_from_xpm_data (struct frame *, const char **);
3094#endif 3094#endif
3095#ifndef x_destroy_bitmap 3095#ifndef x_destroy_bitmap
3096extern void x_destroy_bitmap (struct frame *, int); 3096extern void x_destroy_bitmap (struct frame *, ptrdiff_t);
3097#endif 3097#endif
3098extern void x_destroy_all_bitmaps (Display_Info *); 3098extern void x_destroy_all_bitmaps (Display_Info *);
3099extern int x_create_bitmap_mask (struct frame * , int); 3099extern int x_create_bitmap_mask (struct frame *, ptrdiff_t);
3100extern Lisp_Object x_find_image_file (Lisp_Object); 3100extern Lisp_Object x_find_image_file (Lisp_Object);
3101 3101
3102void x_kill_gs_process (Pixmap, struct frame *); 3102void x_kill_gs_process (Pixmap, struct frame *);
diff --git a/src/editfns.c b/src/editfns.c
index 2d736bbc7e2..c0c0e530265 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -86,21 +86,7 @@ extern Lisp_Object w32_get_internal_run_time (void);
86 86
87static void time_overflow (void) NO_RETURN; 87static void time_overflow (void) NO_RETURN;
88static int tm_diff (struct tm *, struct tm *); 88static int tm_diff (struct tm *, struct tm *);
89static void find_field (Lisp_Object, Lisp_Object, Lisp_Object,
90 EMACS_INT *, Lisp_Object, EMACS_INT *);
91static void update_buffer_properties (EMACS_INT, EMACS_INT); 89static void update_buffer_properties (EMACS_INT, EMACS_INT);
92static Lisp_Object region_limit (int);
93static size_t emacs_nmemftime (char *, size_t, const char *,
94 size_t, const struct tm *, int, int);
95static void general_insert_function (void (*) (const char *, EMACS_INT),
96 void (*) (Lisp_Object, EMACS_INT,
97 EMACS_INT, EMACS_INT,
98 EMACS_INT, int),
99 int, ptrdiff_t, Lisp_Object *);
100static Lisp_Object subst_char_in_region_unwind (Lisp_Object);
101static Lisp_Object subst_char_in_region_unwind_1 (Lisp_Object);
102static void transpose_markers (EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT,
103 EMACS_INT, EMACS_INT, EMACS_INT, EMACS_INT);
104 90
105static Lisp_Object Qbuffer_access_fontify_functions; 91static Lisp_Object Qbuffer_access_fontify_functions;
106static Lisp_Object Fuser_full_name (Lisp_Object); 92static Lisp_Object Fuser_full_name (Lisp_Object);
@@ -345,13 +331,13 @@ If you set the marker not to point anywhere, the buffer will have no mark. */)
345 Return the number found, and store them in a vector in VEC 331 Return the number found, and store them in a vector in VEC
346 of length LEN. */ 332 of length LEN. */
347 333
348static int 334static ptrdiff_t
349overlays_around (EMACS_INT pos, Lisp_Object *vec, int len) 335overlays_around (EMACS_INT pos, Lisp_Object *vec, ptrdiff_t len)
350{ 336{
351 Lisp_Object overlay, start, end; 337 Lisp_Object overlay, start, end;
352 struct Lisp_Overlay *tail; 338 struct Lisp_Overlay *tail;
353 EMACS_INT startpos, endpos; 339 EMACS_INT startpos, endpos;
354 int idx = 0; 340 ptrdiff_t idx = 0;
355 341
356 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 342 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
357 { 343 {
@@ -419,7 +405,7 @@ get_pos_property (Lisp_Object position, register Lisp_Object prop, Lisp_Object o
419 else 405 else
420 { 406 {
421 EMACS_INT posn = XINT (position); 407 EMACS_INT posn = XINT (position);
422 int noverlays; 408 ptrdiff_t noverlays;
423 Lisp_Object *overlay_vec, tem; 409 Lisp_Object *overlay_vec, tem;
424 struct buffer *obuf = current_buffer; 410 struct buffer *obuf = current_buffer;
425 411
diff --git a/src/emacs.c b/src/emacs.c
index d14acd63587..c4b4caad9b5 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -585,7 +585,7 @@ argmatch (char **argv, int argc, const char *sstr, const char *lstr,
585 int minlen, char **valptr, int *skipptr) 585 int minlen, char **valptr, int *skipptr)
586{ 586{
587 char *p = NULL; 587 char *p = NULL;
588 int arglen; 588 ptrdiff_t arglen;
589 char *arg; 589 char *arg;
590 590
591 /* Don't access argv[argc]; give up in advance. */ 591 /* Don't access argv[argc]; give up in advance. */
@@ -1087,7 +1087,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1087 dname_arg2[0] = '\0'; 1087 dname_arg2[0] = '\0';
1088 sscanf (dname_arg, "\n%d,%d\n%s", &(daemon_pipe[0]), &(daemon_pipe[1]), 1088 sscanf (dname_arg, "\n%d,%d\n%s", &(daemon_pipe[0]), &(daemon_pipe[1]),
1089 dname_arg2); 1089 dname_arg2);
1090 dname_arg = strlen (dname_arg2) ? dname_arg2 : NULL; 1090 dname_arg = *dname_arg2 ? dname_arg2 : NULL;
1091 } 1091 }
1092#endif /* NS_IMPL_COCOA */ 1092#endif /* NS_IMPL_COCOA */
1093 1093
@@ -1846,8 +1846,7 @@ sort_args (int argc, char **argv)
1846 priority[from] = 0; 1846 priority[from] = 0;
1847 if (argv[from][0] == '-') 1847 if (argv[from][0] == '-')
1848 { 1848 {
1849 int match, thislen; 1849 int match;
1850 char *equals;
1851 1850
1852 /* If we have found "--", don't consider 1851 /* If we have found "--", don't consider
1853 any more arguments as options. */ 1852 any more arguments as options. */
@@ -1879,11 +1878,11 @@ sort_args (int argc, char **argv)
1879 >= 0 (the table index of the match) if just one match so far. */ 1878 >= 0 (the table index of the match) if just one match so far. */
1880 if (argv[from][1] == '-') 1879 if (argv[from][1] == '-')
1881 { 1880 {
1881 char const *equals = strchr (argv[from], '=');
1882 ptrdiff_t thislen =
1883 equals ? equals - argv[from] : strlen (argv[from]);
1884
1882 match = -1; 1885 match = -1;
1883 thislen = strlen (argv[from]);
1884 equals = strchr (argv[from], '=');
1885 if (equals != 0)
1886 thislen = equals - argv[from];
1887 1886
1888 for (i = 0; 1887 for (i = 0;
1889 i < sizeof (standard_args) / sizeof (standard_args[0]); i++) 1888 i < sizeof (standard_args) / sizeof (standard_args[0]); i++)
diff --git a/src/fileio.c b/src/fileio.c
index dd34872c263..824df8172e7 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -440,11 +440,9 @@ get a current directory to run processes in. */)
440static char * 440static char *
441file_name_as_directory (char *out, const char *in) 441file_name_as_directory (char *out, const char *in)
442{ 442{
443 int size = strlen (in) - 1; 443 ptrdiff_t len = strlen (in);
444 444
445 strcpy (out, in); 445 if (len == 0)
446
447 if (size < 0)
448 { 446 {
449 out[0] = '.'; 447 out[0] = '.';
450 out[1] = '/'; 448 out[1] = '/';
@@ -452,11 +450,13 @@ file_name_as_directory (char *out, const char *in)
452 return out; 450 return out;
453 } 451 }
454 452
453 strcpy (out, in);
454
455 /* For Unix syntax, Append a slash if necessary */ 455 /* For Unix syntax, Append a slash if necessary */
456 if (!IS_DIRECTORY_SEP (out[size])) 456 if (!IS_DIRECTORY_SEP (out[len - 1]))
457 { 457 {
458 out[size + 1] = DIRECTORY_SEP; 458 out[len] = DIRECTORY_SEP;
459 out[size + 2] = '\0'; 459 out[len + 1] = '\0';
460 } 460 }
461#ifdef DOS_NT 461#ifdef DOS_NT
462 dostounix_filename (out); 462 dostounix_filename (out);
@@ -503,7 +503,7 @@ For a Unix-syntax file name, just appends a slash. */)
503static int 503static int
504directory_file_name (char *src, char *dst) 504directory_file_name (char *src, char *dst)
505{ 505{
506 long slen; 506 ptrdiff_t slen;
507 507
508 slen = strlen (src); 508 slen = strlen (src);
509 509
@@ -587,9 +587,9 @@ make_temp_name (Lisp_Object prefix, int base64_p)
587{ 587{
588 Lisp_Object val; 588 Lisp_Object val;
589 int len, clen; 589 int len, clen;
590 int pid; 590 intmax_t pid;
591 char *p, *data; 591 char *p, *data;
592 char pidbuf[20]; 592 char pidbuf[INT_BUFSIZE_BOUND (pid_t)];
593 int pidlen; 593 int pidlen;
594 594
595 CHECK_STRING (prefix); 595 CHECK_STRING (prefix);
@@ -599,7 +599,7 @@ make_temp_name (Lisp_Object prefix, int base64_p)
599 three are incremented if the file already exists. This ensures 599 three are incremented if the file already exists. This ensures
600 262144 unique file names per PID per PREFIX. */ 600 262144 unique file names per PID per PREFIX. */
601 601
602 pid = (int) getpid (); 602 pid = getpid ();
603 603
604 if (base64_p) 604 if (base64_p)
605 { 605 {
@@ -611,8 +611,7 @@ make_temp_name (Lisp_Object prefix, int base64_p)
611 else 611 else
612 { 612 {
613#ifdef HAVE_LONG_FILE_NAMES 613#ifdef HAVE_LONG_FILE_NAMES
614 sprintf (pidbuf, "%d", pid); 614 pidlen = sprintf (pidbuf, "%"PRIdMAX, pid);
615 pidlen = strlen (pidbuf);
616#else 615#else
617 pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6; 616 pidbuf[0] = make_temp_name_tbl[pid & 63], pid >>= 6;
618 pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6; 617 pidbuf[1] = make_temp_name_tbl[pid & 63], pid >>= 6;
@@ -737,14 +736,14 @@ filesystem tree, not (expand-file-name ".." dirname). */)
737 /* This should only point to alloca'd data. */ 736 /* This should only point to alloca'd data. */
738 char *target; 737 char *target;
739 738
740 int tlen; 739 ptrdiff_t tlen;
741 struct passwd *pw; 740 struct passwd *pw;
742#ifdef DOS_NT 741#ifdef DOS_NT
743 int drive = 0; 742 int drive = 0;
744 int collapse_newdir = 1; 743 int collapse_newdir = 1;
745 int is_escaped = 0; 744 int is_escaped = 0;
746#endif /* DOS_NT */ 745#endif /* DOS_NT */
747 int length; 746 ptrdiff_t length;
748 Lisp_Object handler, result; 747 Lisp_Object handler, result;
749 int multibyte; 748 int multibyte;
750 Lisp_Object hdir; 749 Lisp_Object hdir;
@@ -1314,7 +1313,7 @@ See also the function `substitute-in-file-name'.")
1314 unsigned char *nm; 1313 unsigned char *nm;
1315 1314
1316 register unsigned char *newdir, *p, *o; 1315 register unsigned char *newdir, *p, *o;
1317 int tlen; 1316 ptrdiff_t tlen;
1318 unsigned char *target; 1317 unsigned char *target;
1319 struct passwd *pw; 1318 struct passwd *pw;
1320 int lose; 1319 int lose;
@@ -1366,7 +1365,7 @@ See also the function `substitute-in-file-name'.")
1366 unsigned char *user = nm + 1; 1365 unsigned char *user = nm + 1;
1367 /* Find end of name. */ 1366 /* Find end of name. */
1368 unsigned char *ptr = (unsigned char *) strchr (user, '/'); 1367 unsigned char *ptr = (unsigned char *) strchr (user, '/');
1369 int len = ptr ? ptr - user : strlen (user); 1368 ptrdiff_t len = ptr ? ptr - user : strlen (user);
1370 /* Copy the user name into temp storage. */ 1369 /* Copy the user name into temp storage. */
1371 o = (unsigned char *) alloca (len + 1); 1370 o = (unsigned char *) alloca (len + 1);
1372 memcpy (o, user, len); 1371 memcpy (o, user, len);
@@ -1672,7 +1671,7 @@ those `/' is discarded. */)
1672 else 1671 else
1673 { 1672 {
1674 Lisp_Object orig, decoded; 1673 Lisp_Object orig, decoded;
1675 int orig_length, decoded_length; 1674 ptrdiff_t orig_length, decoded_length;
1676 orig_length = strlen (o); 1675 orig_length = strlen (o);
1677 orig = make_unibyte_string (o, orig_length); 1676 orig = make_unibyte_string (o, orig_length);
1678 decoded = DECODE_FILE (orig); 1677 decoded = DECODE_FILE (orig);
diff --git a/src/filelock.c b/src/filelock.c
index 13b27c72f19..18483b6f3f3 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -168,7 +168,7 @@ get_boot_time (void)
168 /* If we did not find a boot time in wtmp, look at wtmp, and so on. */ 168 /* If we did not find a boot time in wtmp, look at wtmp, and so on. */
169 for (counter = 0; counter < 20 && ! boot_time; counter++) 169 for (counter = 0; counter < 20 && ! boot_time; counter++)
170 { 170 {
171 char cmd_string[100]; 171 char cmd_string[sizeof WTMP_FILE ".19.gz"];
172 Lisp_Object tempname, filename; 172 Lisp_Object tempname, filename;
173 int delete_flag = 0; 173 int delete_flag = 0;
174 174
@@ -191,19 +191,16 @@ get_boot_time (void)
191 character long prefix, and call make_temp_file with 191 character long prefix, and call make_temp_file with
192 second arg non-zero, so that it will add not more 192 second arg non-zero, so that it will add not more
193 than 6 characters to the prefix. */ 193 than 6 characters to the prefix. */
194 tempname = Fexpand_file_name (build_string ("wt"), 194 filename = Fexpand_file_name (build_string ("wt"),
195 Vtemporary_file_directory); 195 Vtemporary_file_directory);
196 tempname = make_temp_name (tempname, 1); 196 filename = make_temp_name (filename, 1);
197 args[0] = Vshell_file_name; 197 args[0] = build_string ("gzip");
198 args[1] = Qnil; 198 args[1] = Qnil;
199 args[2] = Qnil; 199 args[2] = list2 (QCfile, filename);
200 args[3] = Qnil; 200 args[3] = Qnil;
201 args[4] = build_string ("-c"); 201 args[4] = build_string ("-cd");
202 sprintf (cmd_string, "gunzip < %s.%d.gz > %s", 202 args[5] = tempname;
203 WTMP_FILE, counter, SDATA (tempname));
204 args[5] = build_string (cmd_string);
205 Fcall_process (6, args); 203 Fcall_process (6, args);
206 filename = tempname;
207 delete_flag = 1; 204 delete_flag = 1;
208 } 205 }
209 } 206 }
@@ -284,14 +281,10 @@ typedef struct
284{ 281{
285 char *user; 282 char *user;
286 char *host; 283 char *host;
287 unsigned long pid; 284 pid_t pid;
288 time_t boot_time; 285 time_t boot_time;
289} lock_info_type; 286} lock_info_type;
290 287
291/* When we read the info back, we might need this much more,
292 enough for decimal representation plus null. */
293#define LOCK_PID_MAX (4 * sizeof (unsigned long))
294
295/* Free the two dynamically-allocated pieces in PTR. */ 288/* Free the two dynamically-allocated pieces in PTR. */
296#define FREE_LOCK_INFO(i) do { xfree ((i).user); xfree ((i).host); } while (0) 289#define FREE_LOCK_INFO(i) do { xfree ((i).user); xfree ((i).host); } while (0)
297 290
@@ -344,7 +337,7 @@ static int
344lock_file_1 (char *lfname, int force) 337lock_file_1 (char *lfname, int force)
345{ 338{
346 register int err; 339 register int err;
347 time_t boot; 340 intmax_t boot, pid;
348 const char *user_name; 341 const char *user_name;
349 const char *host_name; 342 const char *host_name;
350 char *lock_info_str; 343 char *lock_info_str;
@@ -361,14 +354,16 @@ lock_file_1 (char *lfname, int force)
361 else 354 else
362 host_name = ""; 355 host_name = "";
363 lock_info_str = (char *)alloca (strlen (user_name) + strlen (host_name) 356 lock_info_str = (char *)alloca (strlen (user_name) + strlen (host_name)
364 + LOCK_PID_MAX + 30); 357 + 2 * INT_STRLEN_BOUND (intmax_t)
358 + sizeof "@.:");
359 pid = getpid ();
365 360
366 if (boot) 361 if (boot)
367 sprintf (lock_info_str, "%s@%s.%lu:%lu", user_name, host_name, 362 sprintf (lock_info_str, "%s@%s.%"PRIdMAX":%"PRIdMAX,
368 (unsigned long) getpid (), (unsigned long) boot); 363 user_name, host_name, pid, boot);
369 else 364 else
370 sprintf (lock_info_str, "%s@%s.%lu", user_name, host_name, 365 sprintf (lock_info_str, "%s@%s.%"PRIdMAX,
371 (unsigned long) getpid ()); 366 user_name, host_name, pid);
372 367
373 err = symlink (lock_info_str, lfname); 368 err = symlink (lock_info_str, lfname);
374 if (errno == EEXIST && force) 369 if (errno == EEXIST && force)
@@ -397,8 +392,9 @@ static int
397current_lock_owner (lock_info_type *owner, char *lfname) 392current_lock_owner (lock_info_type *owner, char *lfname)
398{ 393{
399 int ret; 394 int ret;
400 size_t len; 395 ptrdiff_t len;
401 int local_owner = 0; 396 lock_info_type local_owner;
397 intmax_t n;
402 char *at, *dot, *colon; 398 char *at, *dot, *colon;
403 char readlink_buf[READLINK_BUFSIZE]; 399 char readlink_buf[READLINK_BUFSIZE];
404 char *lfinfo = emacs_readlink (lfname, readlink_buf); 400 char *lfinfo = emacs_readlink (lfname, readlink_buf);
@@ -408,12 +404,9 @@ current_lock_owner (lock_info_type *owner, char *lfname)
408 return errno == ENOENT ? 0 : -1; 404 return errno == ENOENT ? 0 : -1;
409 405
410 /* Even if the caller doesn't want the owner info, we still have to 406 /* Even if the caller doesn't want the owner info, we still have to
411 read it to determine return value, so allocate it. */ 407 read it to determine return value. */
412 if (!owner) 408 if (!owner)
413 { 409 owner = &local_owner;
414 owner = (lock_info_type *) alloca (sizeof (lock_info_type));
415 local_owner = 1;
416 }
417 410
418 /* Parse USER@HOST.PID:BOOT_TIME. If can't parse, return -1. */ 411 /* Parse USER@HOST.PID:BOOT_TIME. If can't parse, return -1. */
419 /* The USER is everything before the last @. */ 412 /* The USER is everything before the last @. */
@@ -427,24 +420,34 @@ current_lock_owner (lock_info_type *owner, char *lfname)
427 } 420 }
428 len = at - lfinfo; 421 len = at - lfinfo;
429 owner->user = (char *) xmalloc (len + 1); 422 owner->user = (char *) xmalloc (len + 1);
430 strncpy (owner->user, lfinfo, len); 423 memcpy (owner->user, lfinfo, len);
431 owner->user[len] = 0; 424 owner->user[len] = 0;
432 425
433 /* The PID is everything from the last `.' to the `:'. */ 426 /* The PID is everything from the last `.' to the `:'. */
434 owner->pid = atoi (dot + 1); 427 errno = 0;
435 colon = dot; 428 n = strtoimax (dot + 1, NULL, 10);
436 while (*colon && *colon != ':') 429 owner->pid =
437 colon++; 430 ((0 <= n && n <= TYPE_MAXIMUM (pid_t)
431 && (TYPE_MAXIMUM (pid_t) < INTMAX_MAX || errno != ERANGE))
432 ? n : 0);
433
434 colon = strchr (dot + 1, ':');
438 /* After the `:', if there is one, comes the boot time. */ 435 /* After the `:', if there is one, comes the boot time. */
439 if (*colon == ':') 436 n = 0;
440 owner->boot_time = atoi (colon + 1); 437 if (colon)
441 else 438 {
442 owner->boot_time = 0; 439 errno = 0;
440 n = strtoimax (colon + 1, NULL, 10);
441 }
442 owner->boot_time =
443 ((0 <= n && n <= TYPE_MAXIMUM (time_t)
444 && (TYPE_MAXIMUM (time_t) < INTMAX_MAX || errno != ERANGE))
445 ? n : 0);
443 446
444 /* The host is everything in between. */ 447 /* The host is everything in between. */
445 len = dot - at - 1; 448 len = dot - at - 1;
446 owner->host = (char *) xmalloc (len + 1); 449 owner->host = (char *) xmalloc (len + 1);
447 strncpy (owner->host, at + 1, len); 450 memcpy (owner->host, at + 1, len);
448 owner->host[len] = 0; 451 owner->host[len] = 0;
449 452
450 /* We're done looking at the link info. */ 453 /* We're done looking at the link info. */
@@ -476,7 +479,7 @@ current_lock_owner (lock_info_type *owner, char *lfname)
476 } 479 }
477 480
478 /* Avoid garbage. */ 481 /* Avoid garbage. */
479 if (local_owner || ret <= 0) 482 if (owner == &local_owner || ret <= 0)
480 { 483 {
481 FREE_LOCK_INFO (*owner); 484 FREE_LOCK_INFO (*owner);
482 } 485 }
@@ -539,6 +542,7 @@ lock_file (Lisp_Object fn)
539 register Lisp_Object attack, orig_fn, encoded_fn; 542 register Lisp_Object attack, orig_fn, encoded_fn;
540 register char *lfname, *locker; 543 register char *lfname, *locker;
541 lock_info_type lock_info; 544 lock_info_type lock_info;
545 intmax_t pid;
542 struct gcpro gcpro1; 546 struct gcpro gcpro1;
543 547
544 /* Don't do locking while dumping Emacs. 548 /* Don't do locking while dumping Emacs.
@@ -577,9 +581,10 @@ lock_file (Lisp_Object fn)
577 581
578 /* Else consider breaking the lock */ 582 /* Else consider breaking the lock */
579 locker = (char *) alloca (strlen (lock_info.user) + strlen (lock_info.host) 583 locker = (char *) alloca (strlen (lock_info.user) + strlen (lock_info.host)
580 + LOCK_PID_MAX + 9); 584 + INT_STRLEN_BOUND (intmax_t) + sizeof "@ (pid )");
581 sprintf (locker, "%s@%s (pid %lu)", lock_info.user, lock_info.host, 585 pid = lock_info.pid;
582 lock_info.pid); 586 sprintf (locker, "%s@%s (pid %"PRIdMAX")",
587 lock_info.user, lock_info.host, pid);
583 FREE_LOCK_INFO (lock_info); 588 FREE_LOCK_INFO (lock_info);
584 589
585 attack = call2 (intern ("ask-user-about-lock"), fn, build_string (locker)); 590 attack = call2 (intern ("ask-user-about-lock"), fn, build_string (locker));
diff --git a/src/fns.c b/src/fns.c
index cd7e67360ec..5bf274030a3 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -23,6 +23,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
23#include <time.h> 23#include <time.h>
24#include <setjmp.h> 24#include <setjmp.h>
25 25
26#include <intprops.h>
27
26#include "lisp.h" 28#include "lisp.h"
27#include "commands.h" 29#include "commands.h"
28#include "character.h" 30#include "character.h"
@@ -567,8 +569,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args,
567 } 569 }
568 570
569 result_len += len; 571 result_len += len;
570 if (result_len < 0) 572 if (STRING_BYTES_BOUND < result_len)
571 error ("String overflow"); 573 string_overflow ();
572 } 574 }
573 575
574 if (! some_multibyte) 576 if (! some_multibyte)
@@ -2141,7 +2143,6 @@ ARRAY is a vector, string, char-table, or bool-vector. */)
2141 (Lisp_Object array, Lisp_Object item) 2143 (Lisp_Object array, Lisp_Object item)
2142{ 2144{
2143 register EMACS_INT size, idx; 2145 register EMACS_INT size, idx;
2144 int charval;
2145 2146
2146 if (VECTORP (array)) 2147 if (VECTORP (array))
2147 { 2148 {
@@ -2161,27 +2162,21 @@ ARRAY is a vector, string, char-table, or bool-vector. */)
2161 else if (STRINGP (array)) 2162 else if (STRINGP (array))
2162 { 2163 {
2163 register unsigned char *p = SDATA (array); 2164 register unsigned char *p = SDATA (array);
2164 CHECK_NUMBER (item); 2165 int charval;
2165 charval = XINT (item); 2166 CHECK_CHARACTER (item);
2167 charval = XFASTINT (item);
2166 size = SCHARS (array); 2168 size = SCHARS (array);
2167 if (STRING_MULTIBYTE (array)) 2169 if (STRING_MULTIBYTE (array))
2168 { 2170 {
2169 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2171 unsigned char str[MAX_MULTIBYTE_LENGTH];
2170 int len = CHAR_STRING (charval, str); 2172 int len = CHAR_STRING (charval, str);
2171 EMACS_INT size_byte = SBYTES (array); 2173 EMACS_INT size_byte = SBYTES (array);
2172 unsigned char *p1 = p, *endp = p + size_byte;
2173 int i;
2174 2174
2175 if (size != size_byte) 2175 if (INT_MULTIPLY_OVERFLOW (SCHARS (array), len)
2176 while (p1 < endp) 2176 || SCHARS (array) * len != size_byte)
2177 { 2177 error ("Attempt to change byte length of a string");
2178 int this_len = BYTES_BY_CHAR_HEAD (*p1); 2178 for (idx = 0; idx < size_byte; idx++)
2179 if (len != this_len) 2179 *p++ = str[idx % len];
2180 error ("Attempt to change byte length of a string");
2181 p1 += this_len;
2182 }
2183 for (i = 0; i < size_byte; i++)
2184 *p++ = str[i % len];
2185 } 2180 }
2186 else 2181 else
2187 for (idx = 0; idx < size; idx++) 2182 for (idx = 0; idx < size; idx++)
@@ -2190,19 +2185,18 @@ ARRAY is a vector, string, char-table, or bool-vector. */)
2190 else if (BOOL_VECTOR_P (array)) 2185 else if (BOOL_VECTOR_P (array))
2191 { 2186 {
2192 register unsigned char *p = XBOOL_VECTOR (array)->data; 2187 register unsigned char *p = XBOOL_VECTOR (array)->data;
2193 int size_in_chars 2188 EMACS_INT size_in_chars;
2194 = ((XBOOL_VECTOR (array)->size + BOOL_VECTOR_BITS_PER_CHAR - 1) 2189 size = XBOOL_VECTOR (array)->size;
2190 size_in_chars
2191 = ((size + BOOL_VECTOR_BITS_PER_CHAR - 1)
2195 / BOOL_VECTOR_BITS_PER_CHAR); 2192 / BOOL_VECTOR_BITS_PER_CHAR);
2196 2193
2197 charval = (! NILP (item) ? -1 : 0); 2194 if (size_in_chars)
2198 for (idx = 0; idx < size_in_chars - 1; idx++)
2199 p[idx] = charval;
2200 if (idx < size_in_chars)
2201 { 2195 {
2202 /* Mask out bits beyond the vector size. */ 2196 memset (p, ! NILP (item) ? -1 : 0, size_in_chars);
2203 if (XBOOL_VECTOR (array)->size % BOOL_VECTOR_BITS_PER_CHAR) 2197
2204 charval &= (1 << (XBOOL_VECTOR (array)->size % BOOL_VECTOR_BITS_PER_CHAR)) - 1; 2198 /* Clear any extraneous bits in the last byte. */
2205 p[idx] = charval; 2199 p[size_in_chars - 1] &= (1 << (size % BOOL_VECTOR_BITS_PER_CHAR)) - 1;
2206 } 2200 }
2207 } 2201 }
2208 else 2202 else
@@ -2316,7 +2310,7 @@ mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq)
2316 { 2310 {
2317 for (i = 0; i < leni; i++) 2311 for (i = 0; i < leni; i++)
2318 { 2312 {
2319 int byte; 2313 unsigned char byte;
2320 byte = XBOOL_VECTOR (seq)->data[i / BOOL_VECTOR_BITS_PER_CHAR]; 2314 byte = XBOOL_VECTOR (seq)->data[i / BOOL_VECTOR_BITS_PER_CHAR];
2321 dummy = (byte & (1 << (i % BOOL_VECTOR_BITS_PER_CHAR))) ? Qt : Qnil; 2315 dummy = (byte & (1 << (i % BOOL_VECTOR_BITS_PER_CHAR))) ? Qt : Qnil;
2322 dummy = call1 (fn, dummy); 2316 dummy = call1 (fn, dummy);
diff --git a/src/font.c b/src/font.c
index ecb61ab6a53..14390335f3c 100644
--- a/src/font.c
+++ b/src/font.c
@@ -232,22 +232,35 @@ static int num_font_drivers;
232 STR. */ 232 STR. */
233 233
234Lisp_Object 234Lisp_Object
235font_intern_prop (const char *str, int len, int force_symbol) 235font_intern_prop (const char *str, ptrdiff_t len, int force_symbol)
236{ 236{
237 int i; 237 ptrdiff_t i;
238 Lisp_Object tem; 238 Lisp_Object tem;
239 Lisp_Object obarray; 239 Lisp_Object obarray;
240 EMACS_INT nbytes, nchars; 240 EMACS_INT nbytes, nchars;
241 241
242 if (len == 1 && *str == '*') 242 if (len == 1 && *str == '*')
243 return Qnil; 243 return Qnil;
244 if (!force_symbol && len >=1 && isdigit (*str)) 244 if (!force_symbol && 0 < len && '0' <= *str && *str <= '9')
245 { 245 {
246 for (i = 1; i < len; i++) 246 for (i = 1; i < len; i++)
247 if (! isdigit (str[i])) 247 if (! ('0' <= str[i] && str[i] <= '9'))
248 break; 248 break;
249 if (i == len) 249 if (i == len)
250 return make_number (atoi (str)); 250 {
251 EMACS_INT n;
252
253 i = 0;
254 for (n = 0; (n += str[i++] - '0') <= MOST_POSITIVE_FIXNUM; n *= 10)
255 {
256 if (i == len)
257 return make_number (n);
258 if (MOST_POSITIVE_FIXNUM / 10 < n)
259 break;
260 }
261
262 xsignal1 (Qoverflow_error, make_string (str, len));
263 }
251 } 264 }
252 265
253 /* The following code is copied from the function intern (in 266 /* The following code is copied from the function intern (in
@@ -982,7 +995,7 @@ font_expand_wildcards (Lisp_Object *field, int n)
982int 995int
983font_parse_xlfd (char *name, Lisp_Object font) 996font_parse_xlfd (char *name, Lisp_Object font)
984{ 997{
985 int len = strlen (name); 998 ptrdiff_t len = strlen (name);
986 int i, j, n; 999 int i, j, n;
987 char *f[XLFD_LAST_INDEX + 1]; 1000 char *f[XLFD_LAST_INDEX + 1];
988 Lisp_Object val; 1001 Lisp_Object val;
@@ -1310,7 +1323,7 @@ font_parse_fcname (char *name, Lisp_Object font)
1310 char *p, *q; 1323 char *p, *q;
1311 char *size_beg = NULL, *size_end = NULL; 1324 char *size_beg = NULL, *size_end = NULL;
1312 char *props_beg = NULL, *family_end = NULL; 1325 char *props_beg = NULL, *family_end = NULL;
1313 int len = strlen (name); 1326 ptrdiff_t len = strlen (name);
1314 1327
1315 if (len == 0) 1328 if (len == 0)
1316 return -1; 1329 return -1;
@@ -1376,7 +1389,7 @@ font_parse_fcname (char *name, Lisp_Object font)
1376 if (*q != '=') 1389 if (*q != '=')
1377 { 1390 {
1378 /* Must be an enumerated value. */ 1391 /* Must be an enumerated value. */
1379 int word_len; 1392 ptrdiff_t word_len;
1380 p = p + 1; 1393 p = p + 1;
1381 word_len = q - p; 1394 word_len = q - p;
1382 val = font_intern_prop (p, q - p, 1); 1395 val = font_intern_prop (p, q - p, 1);
@@ -1452,7 +1465,7 @@ font_parse_fcname (char *name, Lisp_Object font)
1452 Lisp_Object weight = Qnil, slant = Qnil; 1465 Lisp_Object weight = Qnil, slant = Qnil;
1453 Lisp_Object width = Qnil, size = Qnil; 1466 Lisp_Object width = Qnil, size = Qnil;
1454 char *word_start; 1467 char *word_start;
1455 int word_len; 1468 ptrdiff_t word_len;
1456 1469
1457 /* Scan backwards from the end, looking for a size. */ 1470 /* Scan backwards from the end, looking for a size. */
1458 for (p = name + len - 1; p >= name; p--) 1471 for (p = name + len - 1; p >= name; p--)
@@ -1542,7 +1555,8 @@ font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int nbytes)
1542 Lisp_Object family, foundry; 1555 Lisp_Object family, foundry;
1543 Lisp_Object tail, val; 1556 Lisp_Object tail, val;
1544 int point_size; 1557 int point_size;
1545 int i, len = 1; 1558 int i;
1559 ptrdiff_t len = 1;
1546 char *p; 1560 char *p;
1547 Lisp_Object styles[3]; 1561 Lisp_Object styles[3];
1548 const char *style_names[3] = { "weight", "slant", "width" }; 1562 const char *style_names[3] = { "weight", "slant", "width" };
@@ -2093,8 +2107,8 @@ font_score (Lisp_Object entity, Lisp_Object *spec_prop)
2093 { 2107 {
2094 /* We use the higher 6-bit for the actual size difference. The 2108 /* We use the higher 6-bit for the actual size difference. The
2095 lowest bit is set if the DPI is different. */ 2109 lowest bit is set if the DPI is different. */
2096 int diff; 2110 EMACS_INT diff;
2097 int pixel_size = XINT (spec_prop[FONT_SIZE_INDEX]); 2111 EMACS_INT pixel_size = XINT (spec_prop[FONT_SIZE_INDEX]);
2098 2112
2099 if (CONSP (Vface_font_rescale_alist)) 2113 if (CONSP (Vface_font_rescale_alist))
2100 pixel_size *= font_rescale_ratio (entity); 2114 pixel_size *= font_rescale_ratio (entity);
@@ -4294,7 +4308,7 @@ created glyph-string. Otherwise, the value is nil. */)
4294{ 4308{
4295 struct font *font; 4309 struct font *font;
4296 Lisp_Object font_object, n, glyph; 4310 Lisp_Object font_object, n, glyph;
4297 int i, j, from, to; 4311 EMACS_INT i, j, from, to;
4298 4312
4299 if (! composition_gstring_p (gstring)) 4313 if (! composition_gstring_p (gstring))
4300 signal_error ("Invalid glyph-string: ", gstring); 4314 signal_error ("Invalid glyph-string: ", gstring);
diff --git a/src/font.h b/src/font.h
index 0ca9e8baec4..e50eaff9a1f 100644
--- a/src/font.h
+++ b/src/font.h
@@ -777,7 +777,8 @@ extern void font_done_for_face (FRAME_PTR f, struct face *face);
777extern Lisp_Object font_open_by_spec (FRAME_PTR f, Lisp_Object spec); 777extern Lisp_Object font_open_by_spec (FRAME_PTR f, Lisp_Object spec);
778extern Lisp_Object font_open_by_name (FRAME_PTR f, const char *name); 778extern Lisp_Object font_open_by_name (FRAME_PTR f, const char *name);
779 779
780extern Lisp_Object font_intern_prop (const char *str, int len, int force_symbol); 780extern Lisp_Object font_intern_prop (const char *str, ptrdiff_t len,
781 int force_symbol);
781extern void font_update_sort_order (int *order); 782extern void font_update_sort_order (int *order);
782 783
783extern void font_parse_family_registry (Lisp_Object family, 784extern void font_parse_family_registry (Lisp_Object family,
diff --git a/src/ftfont.c b/src/ftfont.c
index 5037d54bc2f..4e313a89021 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -2385,8 +2385,8 @@ static Lisp_Object
2385ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font, 2385ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font,
2386 FT_Face ft_face, OTF *otf, FT_Matrix *matrix) 2386 FT_Face ft_face, OTF *otf, FT_Matrix *matrix)
2387{ 2387{
2388 EMACS_UINT len = LGSTRING_GLYPH_LEN (lgstring); 2388 EMACS_INT len = LGSTRING_GLYPH_LEN (lgstring);
2389 EMACS_UINT i; 2389 EMACS_INT i;
2390 struct MFLTFontFT flt_font_ft; 2390 struct MFLTFontFT flt_font_ft;
2391 MFLT *flt = NULL; 2391 MFLT *flt = NULL;
2392 int with_variation_selector = 0; 2392 int with_variation_selector = 0;
@@ -2412,7 +2412,10 @@ ftfont_shape_by_flt (Lisp_Object lgstring, struct font *font,
2412 if (CHAR_VARIATION_SELECTOR_P (c)) 2412 if (CHAR_VARIATION_SELECTOR_P (c))
2413 with_variation_selector++; 2413 with_variation_selector++;
2414 } 2414 }
2415
2415 len = i; 2416 len = i;
2417 lint_assume (len <= TYPE_MAXIMUM (EMACS_INT) - 2);
2418
2416 if (with_variation_selector) 2419 if (with_variation_selector)
2417 { 2420 {
2418 setup_otf_gstring (len); 2421 setup_otf_gstring (len);
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 45f112ae9e5..6c00058e7af 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -1015,7 +1015,7 @@ style_changed_cb (GObject *go,
1015 1015
1016 EVENT_INIT (event); 1016 EVENT_INIT (event);
1017 event.kind = CONFIG_CHANGED_EVENT; 1017 event.kind = CONFIG_CHANGED_EVENT;
1018 event.frame_or_window = make_string (display_name, strlen (display_name)); 1018 event.frame_or_window = build_string (display_name);
1019 /* Theme doesn't change often, so intern is called seldom. */ 1019 /* Theme doesn't change often, so intern is called seldom. */
1020 event.arg = intern ("theme-name"); 1020 event.arg = intern ("theme-name");
1021 kbd_buffer_store_event (&event); 1021 kbd_buffer_store_event (&event);
@@ -1024,7 +1024,7 @@ style_changed_cb (GObject *go,
1024 1024
1025 /* If scroll bar width changed, we need set the new size on all frames 1025 /* If scroll bar width changed, we need set the new size on all frames
1026 on this display. */ 1026 on this display. */
1027 if (dpy) 1027 if (dpy)
1028 { 1028 {
1029 Lisp_Object rest, frame; 1029 Lisp_Object rest, frame;
1030 FOR_EACH_FRAME (rest, frame) 1030 FOR_EACH_FRAME (rest, frame)
diff --git a/src/image.c b/src/image.c
index 495bfdc0eef..a9785e5d00f 100644
--- a/src/image.c
+++ b/src/image.c
@@ -182,20 +182,20 @@ XPutPixel (XImagePtr ximage, int x, int y, unsigned long pixel)
182/* Functions to access the contents of a bitmap, given an id. */ 182/* Functions to access the contents of a bitmap, given an id. */
183 183
184int 184int
185x_bitmap_height (FRAME_PTR f, int id) 185x_bitmap_height (FRAME_PTR f, ptrdiff_t id)
186{ 186{
187 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].height; 187 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].height;
188} 188}
189 189
190int 190int
191x_bitmap_width (FRAME_PTR f, int id) 191x_bitmap_width (FRAME_PTR f, ptrdiff_t id)
192{ 192{
193 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].width; 193 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].width;
194} 194}
195 195
196#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) 196#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
197int 197int
198x_bitmap_pixmap (FRAME_PTR f, int id) 198x_bitmap_pixmap (FRAME_PTR f, ptrdiff_t id)
199{ 199{
200 return (int) FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap; 200 return (int) FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap;
201} 201}
@@ -203,7 +203,7 @@ x_bitmap_pixmap (FRAME_PTR f, int id)
203 203
204#ifdef HAVE_X_WINDOWS 204#ifdef HAVE_X_WINDOWS
205int 205int
206x_bitmap_mask (FRAME_PTR f, int id) 206x_bitmap_mask (FRAME_PTR f, ptrdiff_t id)
207{ 207{
208 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].mask; 208 return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].mask;
209} 209}
@@ -211,11 +211,11 @@ x_bitmap_mask (FRAME_PTR f, int id)
211 211
212/* Allocate a new bitmap record. Returns index of new record. */ 212/* Allocate a new bitmap record. Returns index of new record. */
213 213
214static int 214static ptrdiff_t
215x_allocate_bitmap_record (FRAME_PTR f) 215x_allocate_bitmap_record (FRAME_PTR f)
216{ 216{
217 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 217 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
218 int i; 218 ptrdiff_t i;
219 219
220 if (dpyinfo->bitmaps == NULL) 220 if (dpyinfo->bitmaps == NULL)
221 { 221 {
@@ -233,6 +233,9 @@ x_allocate_bitmap_record (FRAME_PTR f)
233 if (dpyinfo->bitmaps[i].refcount == 0) 233 if (dpyinfo->bitmaps[i].refcount == 0)
234 return i + 1; 234 return i + 1;
235 235
236 if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Bitmap_Record) / 2
237 < dpyinfo->bitmaps_size)
238 memory_full (SIZE_MAX);
236 dpyinfo->bitmaps_size *= 2; 239 dpyinfo->bitmaps_size *= 2;
237 dpyinfo->bitmaps 240 dpyinfo->bitmaps
238 = (Bitmap_Record *) xrealloc (dpyinfo->bitmaps, 241 = (Bitmap_Record *) xrealloc (dpyinfo->bitmaps,
@@ -250,11 +253,11 @@ x_reference_bitmap (FRAME_PTR f, int id)
250 253
251/* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */ 254/* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */
252 255
253int 256ptrdiff_t
254x_create_bitmap_from_data (struct frame *f, char *bits, unsigned int width, unsigned int height) 257x_create_bitmap_from_data (struct frame *f, char *bits, unsigned int width, unsigned int height)
255{ 258{
256 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 259 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
257 int id; 260 ptrdiff_t id;
258 261
259#ifdef HAVE_X_WINDOWS 262#ifdef HAVE_X_WINDOWS
260 Pixmap bitmap; 263 Pixmap bitmap;
@@ -309,7 +312,7 @@ x_create_bitmap_from_data (struct frame *f, char *bits, unsigned int width, unsi
309 312
310/* Create bitmap from file FILE for frame F. */ 313/* Create bitmap from file FILE for frame F. */
311 314
312int 315ptrdiff_t
313x_create_bitmap_from_file (struct frame *f, Lisp_Object file) 316x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
314{ 317{
315 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 318 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
@@ -319,7 +322,7 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
319#endif /* HAVE_NTGUI */ 322#endif /* HAVE_NTGUI */
320 323
321#ifdef HAVE_NS 324#ifdef HAVE_NS
322 int id; 325 ptrdiff_t id;
323 void *bitmap = ns_image_from_file (file); 326 void *bitmap = ns_image_from_file (file);
324 327
325 if (!bitmap) 328 if (!bitmap)
@@ -340,7 +343,8 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
340#ifdef HAVE_X_WINDOWS 343#ifdef HAVE_X_WINDOWS
341 unsigned int width, height; 344 unsigned int width, height;
342 Pixmap bitmap; 345 Pixmap bitmap;
343 int xhot, yhot, result, id; 346 int xhot, yhot, result;
347 ptrdiff_t id;
344 Lisp_Object found; 348 Lisp_Object found;
345 int fd; 349 int fd;
346 char *filename; 350 char *filename;
@@ -413,7 +417,7 @@ free_bitmap_record (Display_Info *dpyinfo, Bitmap_Record *bm)
413/* Remove reference to bitmap with id number ID. */ 417/* Remove reference to bitmap with id number ID. */
414 418
415void 419void
416x_destroy_bitmap (FRAME_PTR f, int id) 420x_destroy_bitmap (FRAME_PTR f, ptrdiff_t id)
417{ 421{
418 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 422 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
419 423
@@ -435,7 +439,7 @@ x_destroy_bitmap (FRAME_PTR f, int id)
435void 439void
436x_destroy_all_bitmaps (Display_Info *dpyinfo) 440x_destroy_all_bitmaps (Display_Info *dpyinfo)
437{ 441{
438 int i; 442 ptrdiff_t i;
439 Bitmap_Record *bm = dpyinfo->bitmaps; 443 Bitmap_Record *bm = dpyinfo->bitmaps;
440 444
441 for (i = 0; i < dpyinfo->bitmaps_last; i++, bm++) 445 for (i = 0; i < dpyinfo->bitmaps_last; i++, bm++)
@@ -467,7 +471,7 @@ static void x_destroy_x_image (XImagePtr ximg);
467 It's nicer with some borders in this context */ 471 It's nicer with some borders in this context */
468 472
469int 473int
470x_create_bitmap_mask (struct frame *f, int id) 474x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
471{ 475{
472 Pixmap pixmap, mask; 476 Pixmap pixmap, mask;
473 XImagePtr ximg, mask_img; 477 XImagePtr ximg, mask_img;
@@ -2308,7 +2312,7 @@ xbm_image_p (Lisp_Object object)
2308 else 2312 else
2309 { 2313 {
2310 Lisp_Object data; 2314 Lisp_Object data;
2311 int width, height; 2315 EMACS_INT width, height;
2312 2316
2313 /* Entries for `:width', `:height' and `:data' must be present. */ 2317 /* Entries for `:width', `:height' and `:data' must be present. */
2314 if (!kw[XBM_WIDTH].count 2318 if (!kw[XBM_WIDTH].count
@@ -2324,7 +2328,7 @@ xbm_image_p (Lisp_Object object)
2324 data. */ 2328 data. */
2325 if (VECTORP (data)) 2329 if (VECTORP (data))
2326 { 2330 {
2327 int i; 2331 EMACS_INT i;
2328 2332
2329 /* Number of elements of the vector must be >= height. */ 2333 /* Number of elements of the vector must be >= height. */
2330 if (ASIZE (data) < height) 2334 if (ASIZE (data) < height)
@@ -2829,6 +2833,7 @@ xbm_load (struct frame *f, struct image *img)
2829 } 2833 }
2830 2834
2831 success_p = xbm_load_image (f, img, contents, contents + size); 2835 success_p = xbm_load_image (f, img, contents, contents + size);
2836 xfree (contents);
2832 } 2837 }
2833 else 2838 else
2834 { 2839 {
@@ -3281,11 +3286,12 @@ xpm_image_p (Lisp_Object object)
3281#endif /* HAVE_XPM || HAVE_NS */ 3286#endif /* HAVE_XPM || HAVE_NS */
3282 3287
3283#if defined HAVE_XPM && defined HAVE_X_WINDOWS && !defined USE_GTK 3288#if defined HAVE_XPM && defined HAVE_X_WINDOWS && !defined USE_GTK
3284int 3289ptrdiff_t
3285x_create_bitmap_from_xpm_data (struct frame *f, const char **bits) 3290x_create_bitmap_from_xpm_data (struct frame *f, const char **bits)
3286{ 3291{
3287 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 3292 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3288 int id, rc; 3293 ptrdiff_t id;
3294 int rc;
3289 XpmAttributes attrs; 3295 XpmAttributes attrs;
3290 Pixmap bitmap, mask; 3296 Pixmap bitmap, mask;
3291 3297
@@ -3589,25 +3595,14 @@ xpm_load (struct frame *f, struct image *img)
3589/* XPM support functions for NS where libxpm is not available. 3595/* XPM support functions for NS where libxpm is not available.
3590 Only XPM version 3 (without any extensions) is supported. */ 3596 Only XPM version 3 (without any extensions) is supported. */
3591 3597
3592static int xpm_scan (const unsigned char **, const unsigned char *,
3593 const unsigned char **, int *);
3594static Lisp_Object xpm_make_color_table_v
3595 (void (**) (Lisp_Object, const unsigned char *, int, Lisp_Object),
3596 Lisp_Object (**) (Lisp_Object, const unsigned char *, int));
3597static void xpm_put_color_table_v (Lisp_Object, const unsigned char *, 3598static void xpm_put_color_table_v (Lisp_Object, const unsigned char *,
3598 int, Lisp_Object); 3599 int, Lisp_Object);
3599static Lisp_Object xpm_get_color_table_v (Lisp_Object, 3600static Lisp_Object xpm_get_color_table_v (Lisp_Object,
3600 const unsigned char *, int); 3601 const unsigned char *, int);
3601static Lisp_Object xpm_make_color_table_h
3602 (void (**) (Lisp_Object, const unsigned char *, int, Lisp_Object),
3603 Lisp_Object (**) (Lisp_Object, const unsigned char *, int));
3604static void xpm_put_color_table_h (Lisp_Object, const unsigned char *, 3602static void xpm_put_color_table_h (Lisp_Object, const unsigned char *,
3605 int, Lisp_Object); 3603 int, Lisp_Object);
3606static Lisp_Object xpm_get_color_table_h (Lisp_Object, 3604static Lisp_Object xpm_get_color_table_h (Lisp_Object,
3607 const unsigned char *, int); 3605 const unsigned char *, int);
3608static int xpm_str_to_color_key (const char *);
3609static int xpm_load_image (struct frame *, struct image *,
3610 const unsigned char *, const unsigned char *);
3611 3606
3612/* Tokens returned from xpm_scan. */ 3607/* Tokens returned from xpm_scan. */
3613 3608
@@ -3629,7 +3624,7 @@ static int
3629xpm_scan (const unsigned char **s, 3624xpm_scan (const unsigned char **s,
3630 const unsigned char *end, 3625 const unsigned char *end,
3631 const unsigned char **beg, 3626 const unsigned char **beg,
3632 int *len) 3627 ptrdiff_t *len)
3633{ 3628{
3634 int c; 3629 int c;
3635 3630
@@ -3799,7 +3794,8 @@ xpm_load_image (struct frame *f,
3799 unsigned char buffer[BUFSIZ]; 3794 unsigned char buffer[BUFSIZ];
3800 int width, height, x, y; 3795 int width, height, x, y;
3801 int num_colors, chars_per_pixel; 3796 int num_colors, chars_per_pixel;
3802 int len, LA1; 3797 ptrdiff_t len;
3798 int LA1;
3803 void (*put_color_table) (Lisp_Object, const unsigned char *, int, Lisp_Object); 3799 void (*put_color_table) (Lisp_Object, const unsigned char *, int, Lisp_Object);
3804 Lisp_Object (*get_color_table) (Lisp_Object, const unsigned char *, int); 3800 Lisp_Object (*get_color_table) (Lisp_Object, const unsigned char *, int);
3805 Lisp_Object frame, color_symbols, color_table; 3801 Lisp_Object frame, color_symbols, color_table;
diff --git a/src/indent.c b/src/indent.c
index 57a4548ef3c..02d99d14ded 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -318,6 +318,15 @@ invalidate_current_column (void)
318 last_known_column_point = 0; 318 last_known_column_point = 0;
319} 319}
320 320
321/* Return a non-outlandish value for the tab width. */
322
323static int
324sane_tab_width (void)
325{
326 EMACS_INT n = XFASTINT (BVAR (current_buffer, tab_width));
327 return 0 < n && n <= 1000 ? n : 8;
328}
329
321EMACS_INT 330EMACS_INT
322current_column (void) 331current_column (void)
323{ 332{
@@ -326,7 +335,7 @@ current_column (void)
326 register int tab_seen; 335 register int tab_seen;
327 EMACS_INT post_tab; 336 EMACS_INT post_tab;
328 register int c; 337 register int c;
329 register EMACS_INT tab_width = XINT (BVAR (current_buffer, tab_width)); 338 int tab_width = sane_tab_width ();
330 int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); 339 int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow));
331 register struct Lisp_Char_Table *dp = buffer_display_table (); 340 register struct Lisp_Char_Table *dp = buffer_display_table ();
332 341
@@ -356,9 +365,6 @@ current_column (void)
356 else 365 else
357 stop = GAP_END_ADDR; 366 stop = GAP_END_ADDR;
358 367
359 if (tab_width <= 0 || tab_width > 1000)
360 tab_width = 8;
361
362 col = 0, tab_seen = 0, post_tab = 0; 368 col = 0, tab_seen = 0, post_tab = 0;
363 369
364 while (1) 370 while (1)
@@ -509,7 +515,7 @@ check_display_width (EMACS_INT pos, EMACS_INT col, EMACS_INT *endpos)
509static void 515static void
510scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol) 516scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol)
511{ 517{
512 register EMACS_INT tab_width = XINT (BVAR (current_buffer, tab_width)); 518 int tab_width = sane_tab_width ();
513 register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); 519 register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow));
514 register struct Lisp_Char_Table *dp = buffer_display_table (); 520 register struct Lisp_Char_Table *dp = buffer_display_table ();
515 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 521 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
@@ -535,7 +541,6 @@ scan_for_column (EMACS_INT *endpos, EMACS_INT *goalcol, EMACS_INT *prevcol)
535 window = Fget_buffer_window (Fcurrent_buffer (), Qnil); 541 window = Fget_buffer_window (Fcurrent_buffer (), Qnil);
536 w = ! NILP (window) ? XWINDOW (window) : NULL; 542 w = ! NILP (window) ? XWINDOW (window) : NULL;
537 543
538 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
539 memset (&cmp_it, 0, sizeof cmp_it); 544 memset (&cmp_it, 0, sizeof cmp_it);
540 cmp_it.id = -1; 545 cmp_it.id = -1;
541 composition_compute_stop_pos (&cmp_it, scan, scan_byte, end, Qnil); 546 composition_compute_stop_pos (&cmp_it, scan, scan_byte, end, Qnil);
@@ -728,7 +733,7 @@ string_display_width (string, beg, end)
728 register int tab_seen; 733 register int tab_seen;
729 int post_tab; 734 int post_tab;
730 register int c; 735 register int c;
731 register int tab_width = XINT (current_buffer->tab_width); 736 int tab_width = sane_tab_width ();
732 int ctl_arrow = !NILP (current_buffer->ctl_arrow); 737 int ctl_arrow = !NILP (current_buffer->ctl_arrow);
733 register struct Lisp_Char_Table *dp = buffer_display_table (); 738 register struct Lisp_Char_Table *dp = buffer_display_table ();
734 int b, e; 739 int b, e;
@@ -755,8 +760,6 @@ string_display_width (string, beg, end)
755 going backwards from point. */ 760 going backwards from point. */
756 stop = SDATA (string) + b; 761 stop = SDATA (string) + b;
757 762
758 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
759
760 col = 0, tab_seen = 0, post_tab = 0; 763 col = 0, tab_seen = 0, post_tab = 0;
761 764
762 while (1) 765 while (1)
@@ -806,7 +809,7 @@ The return value is COLUMN. */)
806{ 809{
807 EMACS_INT mincol; 810 EMACS_INT mincol;
808 register EMACS_INT fromcol; 811 register EMACS_INT fromcol;
809 register EMACS_INT tab_width = XINT (BVAR (current_buffer, tab_width)); 812 int tab_width = sane_tab_width ();
810 813
811 CHECK_NUMBER (column); 814 CHECK_NUMBER (column);
812 if (NILP (minimum)) 815 if (NILP (minimum))
@@ -820,8 +823,6 @@ The return value is COLUMN. */)
820 if (fromcol == mincol) 823 if (fromcol == mincol)
821 return make_number (mincol); 824 return make_number (mincol);
822 825
823 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
824
825 if (indent_tabs_mode) 826 if (indent_tabs_mode)
826 { 827 {
827 Lisp_Object n; 828 Lisp_Object n;
@@ -867,15 +868,13 @@ static EMACS_INT
867position_indentation (register int pos_byte) 868position_indentation (register int pos_byte)
868{ 869{
869 register EMACS_INT column = 0; 870 register EMACS_INT column = 0;
870 register EMACS_INT tab_width = XINT (BVAR (current_buffer, tab_width)); 871 int tab_width = sane_tab_width ();
871 register unsigned char *p; 872 register unsigned char *p;
872 register unsigned char *stop; 873 register unsigned char *stop;
873 unsigned char *start; 874 unsigned char *start;
874 EMACS_INT next_boundary_byte = pos_byte; 875 EMACS_INT next_boundary_byte = pos_byte;
875 EMACS_INT ceiling = next_boundary_byte; 876 EMACS_INT ceiling = next_boundary_byte;
876 877
877 if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
878
879 p = BYTE_POS_ADDR (pos_byte); 878 p = BYTE_POS_ADDR (pos_byte);
880 /* STOP records the value of P at which we will need 879 /* STOP records the value of P at which we will need
881 to think about the gap, or about invisible text, 880 to think about the gap, or about invisible text,
@@ -1118,7 +1117,7 @@ compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_
1118 register EMACS_INT pos; 1117 register EMACS_INT pos;
1119 EMACS_INT pos_byte; 1118 EMACS_INT pos_byte;
1120 register int c = 0; 1119 register int c = 0;
1121 register EMACS_INT tab_width = XFASTINT (BVAR (current_buffer, tab_width)); 1120 int tab_width = sane_tab_width ();
1122 register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow)); 1121 register int ctl_arrow = !NILP (BVAR (current_buffer, ctl_arrow));
1123 register struct Lisp_Char_Table *dp = window_display_table (win); 1122 register struct Lisp_Char_Table *dp = window_display_table (win);
1124 EMACS_INT selective 1123 EMACS_INT selective
@@ -1173,9 +1172,6 @@ compute_motion (EMACS_INT from, EMACS_INT fromvpos, EMACS_INT fromhpos, int did_
1173 run cache, because that's based on the buffer's display table. */ 1172 run cache, because that's based on the buffer's display table. */
1174 width_table = 0; 1173 width_table = 0;
1175 1174
1176 if (tab_width <= 0 || tab_width > 1000)
1177 tab_width = 8;
1178
1179 /* Negative width means use all available text columns. */ 1175 /* Negative width means use all available text columns. */
1180 if (width < 0) 1176 if (width < 0)
1181 { 1177 {
@@ -1747,7 +1743,7 @@ visible section of the buffer, and pass LINE and COL as TOPOS. */)
1747 struct window *w; 1743 struct window *w;
1748 Lisp_Object bufpos, hpos, vpos, prevhpos; 1744 Lisp_Object bufpos, hpos, vpos, prevhpos;
1749 struct position *pos; 1745 struct position *pos;
1750 int hscroll, tab_offset; 1746 EMACS_INT hscroll, tab_offset;
1751 1747
1752 CHECK_NUMBER_COERCE_MARKER (from); 1748 CHECK_NUMBER_COERCE_MARKER (from);
1753 CHECK_CONS (frompos); 1749 CHECK_CONS (frompos);
diff --git a/src/insdel.c b/src/insdel.c
index bc95e3ad9e8..c52785cd33d 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -44,12 +44,6 @@ static void insert_from_buffer_1 (struct buffer *buf,
44 int inherit); 44 int inherit);
45static void gap_left (EMACS_INT charpos, EMACS_INT bytepos, int newgap); 45static void gap_left (EMACS_INT charpos, EMACS_INT bytepos, int newgap);
46static void gap_right (EMACS_INT charpos, EMACS_INT bytepos); 46static void gap_right (EMACS_INT charpos, EMACS_INT bytepos);
47static void adjust_markers_for_insert (EMACS_INT from, EMACS_INT from_byte,
48 EMACS_INT to, EMACS_INT to_byte,
49 int before_markers);
50static void adjust_markers_for_replace (EMACS_INT, EMACS_INT, EMACS_INT,
51 EMACS_INT, EMACS_INT, EMACS_INT);
52static void adjust_point (EMACS_INT nchars, EMACS_INT nbytes);
53 47
54static Lisp_Object Fcombine_after_change_execute (void); 48static Lisp_Object Fcombine_after_change_execute (void);
55 49
diff --git a/src/keyboard.c b/src/keyboard.c
index e7a0598e839..bffe2b035dc 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -8225,7 +8225,7 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item)
8225 /* `:label LABEL-STRING'. */ 8225 /* `:label LABEL-STRING'. */
8226 PROP (TOOL_BAR_ITEM_LABEL) = STRINGP (value) 8226 PROP (TOOL_BAR_ITEM_LABEL) = STRINGP (value)
8227 ? value 8227 ? value
8228 : make_string (bad_label, strlen (bad_label)); 8228 : build_string (bad_label);
8229 have_label = 1; 8229 have_label = 1;
8230 } 8230 }
8231 else if (EQ (ikey, QCfilter)) 8231 else if (EQ (ikey, QCfilter))
@@ -8291,7 +8291,7 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item)
8291 else 8291 else
8292 label = ""; 8292 label = "";
8293 8293
8294 new_lbl = Fupcase_initials (make_string (label, strlen (label))); 8294 new_lbl = Fupcase_initials (build_string (label));
8295 if (SCHARS (new_lbl) <= tool_bar_max_label_size) 8295 if (SCHARS (new_lbl) <= tool_bar_max_label_size)
8296 PROP (TOOL_BAR_ITEM_LABEL) = new_lbl; 8296 PROP (TOOL_BAR_ITEM_LABEL) = new_lbl;
8297 else 8297 else
diff --git a/src/lisp.h b/src/lisp.h
index 1e3036344f5..4c9543bdfe8 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -291,7 +291,7 @@ union Lisp_Object
291 { 291 {
292 /* Used for comparing two Lisp_Objects; 292 /* Used for comparing two Lisp_Objects;
293 also, positive integers can be accessed fast this way. */ 293 also, positive integers can be accessed fast this way. */
294 EMACS_UINT i; 294 EMACS_INT i;
295 295
296 struct 296 struct
297 { 297 {
@@ -315,7 +315,7 @@ union Lisp_Object
315 { 315 {
316 /* Used for comparing two Lisp_Objects; 316 /* Used for comparing two Lisp_Objects;
317 also, positive integers can be accessed fast this way. */ 317 also, positive integers can be accessed fast this way. */
318 EMACS_UINT i; 318 EMACS_INT i;
319 319
320 struct 320 struct
321 { 321 {
@@ -494,8 +494,8 @@ enum pvec_type
494#ifdef USE_LSB_TAG 494#ifdef USE_LSB_TAG
495 495
496# define XSET(var, vartype, ptr) \ 496# define XSET(var, vartype, ptr) \
497 (eassert ((((EMACS_UINT) (ptr)) & ((1 << GCTYPEBITS) - 1)) == 0), \ 497 (eassert ((((uintptr_t) (ptr)) & ((1 << GCTYPEBITS) - 1)) == 0), \
498 (var).u.val = ((EMACS_UINT) (ptr)) >> GCTYPEBITS, \ 498 (var).u.val = ((uintptr_t) (ptr)) >> GCTYPEBITS, \
499 (var).u.type = ((char) (vartype))) 499 (var).u.type = ((char) (vartype)))
500 500
501/* Some versions of gcc seem to consider the bitfield width when issuing 501/* Some versions of gcc seem to consider the bitfield width when issuing
@@ -512,7 +512,7 @@ enum pvec_type
512# define XSETFASTINT(a, b) ((a).i = (b)) 512# define XSETFASTINT(a, b) ((a).i = (b))
513 513
514# define XSET(var, vartype, ptr) \ 514# define XSET(var, vartype, ptr) \
515 (((var).s.val = ((EMACS_INT) (ptr))), ((var).s.type = ((char) (vartype)))) 515 (((var).s.val = ((intptr_t) (ptr))), ((var).s.type = ((char) (vartype))))
516 516
517#ifdef DATA_SEG_BITS 517#ifdef DATA_SEG_BITS
518/* DATA_SEG_BITS forces extra bits to be or'd in with any pointers 518/* DATA_SEG_BITS forces extra bits to be or'd in with any pointers
@@ -1013,7 +1013,7 @@ struct Lisp_Bool_Vector
1013 just the subtype information. */ 1013 just the subtype information. */
1014 struct vectorlike_header header; 1014 struct vectorlike_header header;
1015 /* This is the size in bits. */ 1015 /* This is the size in bits. */
1016 EMACS_UINT size; 1016 EMACS_INT size;
1017 /* This contains the actual bits, packed into bytes. */ 1017 /* This contains the actual bits, packed into bytes. */
1018 unsigned char data[1]; 1018 unsigned char data[1];
1019 }; 1019 };
@@ -1890,7 +1890,7 @@ typedef struct {
1890#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ 1890#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
1891 Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ 1891 Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \
1892 static DECL_ALIGN (struct Lisp_Subr, sname) = \ 1892 static DECL_ALIGN (struct Lisp_Subr, sname) = \
1893 { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ 1893 { PVEC_SUBR, \
1894 { .a ## maxargs = fnname }, \ 1894 { .a ## maxargs = fnname }, \
1895 minargs, maxargs, lname, intspec, 0}; \ 1895 minargs, maxargs, lname, intspec, 0}; \
1896 Lisp_Object fnname 1896 Lisp_Object fnname
@@ -2628,7 +2628,7 @@ extern void init_fringe_once (void);
2628/* Defined in image.c */ 2628/* Defined in image.c */
2629extern Lisp_Object QCascent, QCmargin, QCrelief; 2629extern Lisp_Object QCascent, QCmargin, QCrelief;
2630extern Lisp_Object QCconversion; 2630extern Lisp_Object QCconversion;
2631extern int x_bitmap_mask (struct frame *, int); 2631extern int x_bitmap_mask (struct frame *, ptrdiff_t);
2632extern void syms_of_image (void); 2632extern void syms_of_image (void);
2633extern void init_image (void); 2633extern void init_image (void);
2634 2634
@@ -3590,29 +3590,19 @@ extern void init_system_name (void);
3590 3590
3591#define SWITCH_ENUM_CAST(x) (x) 3591#define SWITCH_ENUM_CAST(x) (x)
3592 3592
3593/* Loop over Lisp list LIST. Signal an error if LIST is not a proper 3593/* Use this to suppress gcc's warnings. */
3594 list, or if it contains circles. 3594#ifdef lint
3595
3596 HARE and TORTOISE should be the names of Lisp_Object variables, and
3597 N should be the name of an EMACS_INT variable declared in the
3598 function where the macro is used. Each nested loop should use
3599 its own variables.
3600 3595
3601 In the loop body, HARE is set to each cons of LIST, and N is the 3596/* Use CODE only if lint checking is in effect. */
3602 length of the list processed so far. */ 3597# define IF_LINT(Code) Code
3603 3598
3604#define LIST_END_P(list, obj) \ 3599/* Assume that the expression COND is true. This differs in intent
3605 (NILP (obj) \ 3600 from 'assert', as it is a message from the programmer to the compiler. */
3606 ? 1 \ 3601# define lint_assume(cond) ((cond) ? (void) 0 : abort ())
3607 : (CONSP (obj) \
3608 ? 0 \
3609 : (wrong_type_argument (Qlistp, (list))), 1))
3610 3602
3611/* Use this to suppress gcc's `...may be used before initialized' warnings. */
3612#ifdef lint
3613# define IF_LINT(Code) Code
3614#else 3603#else
3615# define IF_LINT(Code) /* empty */ 3604# define IF_LINT(Code) /* empty */
3605# define lint_assume(cond) ((void) (0 && (cond)))
3616#endif 3606#endif
3617 3607
3618/* The ubiquitous min and max macros. */ 3608/* The ubiquitous min and max macros. */
@@ -3635,9 +3625,7 @@ extern void init_system_name (void);
3635 fixnum. */ 3625 fixnum. */
3636 3626
3637#define make_fixnum_or_float(val) \ 3627#define make_fixnum_or_float(val) \
3638 (FIXNUM_OVERFLOW_P (val) \ 3628 (FIXNUM_OVERFLOW_P (val) ? make_float (val) : make_number (val))
3639 ? make_float (val) \
3640 : make_number ((EMACS_INT)(val)))
3641 3629
3642 3630
3643/* Checks the `cycle check' variable CHECK to see if it indicates that 3631/* Checks the `cycle check' variable CHECK to see if it indicates that
diff --git a/src/lread.c b/src/lread.c
index b789457b223..e75d61ae985 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -158,7 +158,7 @@ static void readevalloop (Lisp_Object, FILE*, Lisp_Object, int,
158static Lisp_Object load_unwind (Lisp_Object); 158static Lisp_Object load_unwind (Lisp_Object);
159static Lisp_Object load_descriptor_unwind (Lisp_Object); 159static Lisp_Object load_descriptor_unwind (Lisp_Object);
160 160
161static void invalid_syntax (const char *, int) NO_RETURN; 161static void invalid_syntax (const char *) NO_RETURN;
162static void end_of_file_error (void) NO_RETURN; 162static void end_of_file_error (void) NO_RETURN;
163 163
164 164
@@ -2014,11 +2014,9 @@ read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end)
2014 S is error string of length N (if > 0) */ 2014 S is error string of length N (if > 0) */
2015 2015
2016static void 2016static void
2017invalid_syntax (const char *s, int n) 2017invalid_syntax (const char *s)
2018{ 2018{
2019 if (!n) 2019 xsignal1 (Qinvalid_read_syntax, build_string (s));
2020 n = strlen (s);
2021 xsignal1 (Qinvalid_read_syntax, make_string (s, n));
2022} 2020}
2023 2021
2024 2022
@@ -2336,7 +2334,7 @@ read_integer (Lisp_Object readcharfun, int radix)
2336 if (! valid) 2334 if (! valid)
2337 { 2335 {
2338 sprintf (buf, "integer, radix %d", radix); 2336 sprintf (buf, "integer, radix %d", radix);
2339 invalid_syntax (buf, 0); 2337 invalid_syntax (buf);
2340 } 2338 }
2341 2339
2342 return string_to_number (buf, radix, 0); 2340 return string_to_number (buf, radix, 0);
@@ -2453,7 +2451,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2453 return ht; 2451 return ht;
2454 } 2452 }
2455 UNREAD (c); 2453 UNREAD (c);
2456 invalid_syntax ("#", 1); 2454 invalid_syntax ("#");
2457 } 2455 }
2458 if (c == '^') 2456 if (c == '^')
2459 { 2457 {
@@ -2487,9 +2485,9 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2487 XSETPVECTYPE (XVECTOR (tmp), PVEC_SUB_CHAR_TABLE); 2485 XSETPVECTYPE (XVECTOR (tmp), PVEC_SUB_CHAR_TABLE);
2488 return tmp; 2486 return tmp;
2489 } 2487 }
2490 invalid_syntax ("#^^", 3); 2488 invalid_syntax ("#^^");
2491 } 2489 }
2492 invalid_syntax ("#^", 2); 2490 invalid_syntax ("#^");
2493 } 2491 }
2494 if (c == '&') 2492 if (c == '&')
2495 { 2493 {
@@ -2513,7 +2511,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2513 version. */ 2511 version. */
2514 && ! (XFASTINT (length) 2512 && ! (XFASTINT (length)
2515 == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR))) 2513 == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR)))
2516 invalid_syntax ("#&...", 5); 2514 invalid_syntax ("#&...");
2517 2515
2518 val = Fmake_bool_vector (length, Qnil); 2516 val = Fmake_bool_vector (length, Qnil);
2519 memcpy (XBOOL_VECTOR (val)->data, SDATA (tmp), size_in_chars); 2517 memcpy (XBOOL_VECTOR (val)->data, SDATA (tmp), size_in_chars);
@@ -2523,7 +2521,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2523 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1; 2521 &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1;
2524 return val; 2522 return val;
2525 } 2523 }
2526 invalid_syntax ("#&...", 5); 2524 invalid_syntax ("#&...");
2527 } 2525 }
2528 if (c == '[') 2526 if (c == '[')
2529 { 2527 {
@@ -2543,7 +2541,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2543 /* Read the string itself. */ 2541 /* Read the string itself. */
2544 tmp = read1 (readcharfun, &ch, 0); 2542 tmp = read1 (readcharfun, &ch, 0);
2545 if (ch != 0 || !STRINGP (tmp)) 2543 if (ch != 0 || !STRINGP (tmp))
2546 invalid_syntax ("#", 1); 2544 invalid_syntax ("#");
2547 GCPRO1 (tmp); 2545 GCPRO1 (tmp);
2548 /* Read the intervals and their properties. */ 2546 /* Read the intervals and their properties. */
2549 while (1) 2547 while (1)
@@ -2559,7 +2557,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2559 if (ch == 0) 2557 if (ch == 0)
2560 plist = read1 (readcharfun, &ch, 0); 2558 plist = read1 (readcharfun, &ch, 0);
2561 if (ch) 2559 if (ch)
2562 invalid_syntax ("Invalid string property list", 0); 2560 invalid_syntax ("Invalid string property list");
2563 Fset_text_properties (beg, end, plist, tmp); 2561 Fset_text_properties (beg, end, plist, tmp);
2564 } 2562 }
2565 UNGCPRO; 2563 UNGCPRO;
@@ -2716,7 +2714,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2716 return read_integer (readcharfun, 2); 2714 return read_integer (readcharfun, 2);
2717 2715
2718 UNREAD (c); 2716 UNREAD (c);
2719 invalid_syntax ("#", 1); 2717 invalid_syntax ("#");
2720 2718
2721 case ';': 2719 case ';':
2722 while ((c = READCHAR) >= 0 && c != '\n'); 2720 while ((c = READCHAR) >= 0 && c != '\n');
@@ -2833,7 +2831,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
2833 if (ok) 2831 if (ok)
2834 return make_number (c); 2832 return make_number (c);
2835 2833
2836 invalid_syntax ("?", 1); 2834 invalid_syntax ("?");
2837 } 2835 }
2838 2836
2839 case '"': 2837 case '"':
@@ -3335,7 +3333,7 @@ string_to_number (char const *string, int base, int ignore_trailing)
3335 /* Unfortunately there's no simple and accurate way to convert 3333 /* Unfortunately there's no simple and accurate way to convert
3336 non-base-10 numbers that are out of C-language range. */ 3334 non-base-10 numbers that are out of C-language range. */
3337 if (base != 10) 3335 if (base != 10)
3338 xsignal (Qoverflow_error, list1 (build_string (string))); 3336 xsignal1 (Qoverflow_error, build_string (string));
3339 } 3337 }
3340 else if (n <= (negative ? -MOST_NEGATIVE_FIXNUM : MOST_POSITIVE_FIXNUM)) 3338 else if (n <= (negative ? -MOST_NEGATIVE_FIXNUM : MOST_POSITIVE_FIXNUM))
3341 { 3339 {
@@ -3501,7 +3499,7 @@ read_list (int flag, register Lisp_Object readcharfun)
3501 { 3499 {
3502 if (ch == ']') 3500 if (ch == ']')
3503 return val; 3501 return val;
3504 invalid_syntax (") or . in a vector", 18); 3502 invalid_syntax (") or . in a vector");
3505 } 3503 }
3506 if (ch == ')') 3504 if (ch == ')')
3507 return val; 3505 return val;
@@ -3603,9 +3601,9 @@ read_list (int flag, register Lisp_Object readcharfun)
3603 3601
3604 return val; 3602 return val;
3605 } 3603 }
3606 invalid_syntax (". in wrong context", 18); 3604 invalid_syntax (". in wrong context");
3607 } 3605 }
3608 invalid_syntax ("] in a list", 11); 3606 invalid_syntax ("] in a list");
3609 } 3607 }
3610 tem = (read_pure && flag <= 0 3608 tem = (read_pure && flag <= 0
3611 ? pure_cons (elt, Qnil) 3609 ? pure_cons (elt, Qnil)
@@ -3652,7 +3650,7 @@ Lisp_Object
3652intern (const char *str) 3650intern (const char *str)
3653{ 3651{
3654 Lisp_Object tem; 3652 Lisp_Object tem;
3655 int len = strlen (str); 3653 ptrdiff_t len = strlen (str);
3656 Lisp_Object obarray; 3654 Lisp_Object obarray;
3657 3655
3658 obarray = Vobarray; 3656 obarray = Vobarray;
@@ -3668,7 +3666,7 @@ Lisp_Object
3668intern_c_string (const char *str) 3666intern_c_string (const char *str)
3669{ 3667{
3670 Lisp_Object tem; 3668 Lisp_Object tem;
3671 int len = strlen (str); 3669 ptrdiff_t len = strlen (str);
3672 Lisp_Object obarray; 3670 Lisp_Object obarray;
3673 3671
3674 obarray = Vobarray; 3672 obarray = Vobarray;
diff --git a/src/minibuf.c b/src/minibuf.c
index 1b555035cfe..ca2f22df9ed 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1115,7 +1115,7 @@ function, instead of the usual behavior. */)
1115{ 1115{
1116 Lisp_Object args[4], result; 1116 Lisp_Object args[4], result;
1117 char *s; 1117 char *s;
1118 int len; 1118 ptrdiff_t len;
1119 int count = SPECPDL_INDEX (); 1119 int count = SPECPDL_INDEX ();
1120 1120
1121 if (BUFFERP (def)) 1121 if (BUFFERP (def))
@@ -1137,7 +1137,7 @@ function, instead of the usual behavior. */)
1137 if (STRINGP (prompt)) 1137 if (STRINGP (prompt))
1138 { 1138 {
1139 s = SSDATA (prompt); 1139 s = SSDATA (prompt);
1140 len = strlen (s); 1140 len = SBYTES (prompt);
1141 if (len >= 2 && s[len - 2] == ':' && s[len - 1] == ' ') 1141 if (len >= 2 && s[len - 2] == ':' && s[len - 1] == ' ')
1142 len = len - 2; 1142 len = len - 2;
1143 else if (len >= 1 && (s[len - 1] == ':' || s[len - 1] == ' ')) 1143 else if (len >= 1 && (s[len - 1] == ':' || s[len - 1] == ' '))
diff --git a/src/nsterm.h b/src/nsterm.h
index 09ec8c19b1a..7459087c988 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -468,8 +468,8 @@ struct ns_display_info
468 int smallest_font_height; 468 int smallest_font_height;
469 469
470 struct ns_bitmap_record *bitmaps; 470 struct ns_bitmap_record *bitmaps;
471 int bitmaps_size; 471 ptrdiff_t bitmaps_size;
472 int bitmaps_last; 472 ptrdiff_t bitmaps_last;
473 473
474 struct image_cache *image_cache; 474 struct image_cache *image_cache;
475 475
@@ -818,4 +818,3 @@ extern char gnustep_base_version[]; /* version tracking */
818 818
819 819
820#endif /* HAVE_NS */ 820#endif /* HAVE_NS */
821
diff --git a/src/process.c b/src/process.c
index e5189c6981c..0040d14a0f6 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1187,7 +1187,7 @@ Returns nil if format of ADDRESS is invalid. */)
1187 if (VECTORP (address)) /* AF_INET or AF_INET6 */ 1187 if (VECTORP (address)) /* AF_INET or AF_INET6 */
1188 { 1188 {
1189 register struct Lisp_Vector *p = XVECTOR (address); 1189 register struct Lisp_Vector *p = XVECTOR (address);
1190 EMACS_UINT size = p->header.size; 1190 EMACS_INT size = p->header.size;
1191 Lisp_Object args[10]; 1191 Lisp_Object args[10];
1192 int nargs, i; 1192 int nargs, i;
1193 1193
diff --git a/src/termcap.c b/src/termcap.c
index 5b71ad229d7..e191f6b3af3 100644
--- a/src/termcap.c
+++ b/src/termcap.c
@@ -323,10 +323,10 @@ tputs (register const char *str, int nlines, int (*outfun) (int))
323struct termcap_buffer 323struct termcap_buffer
324 { 324 {
325 char *beg; 325 char *beg;
326 int size; 326 ptrdiff_t size;
327 char *ptr; 327 char *ptr;
328 int ateof; 328 int ateof;
329 int full; 329 ptrdiff_t full;
330 }; 330 };
331 331
332/* Forward declarations of static functions. */ 332/* Forward declarations of static functions. */
@@ -367,7 +367,7 @@ tgetent (char *bp, const char *name)
367 register char *bp1; 367 register char *bp1;
368 char *tc_search_point; 368 char *tc_search_point;
369 char *term; 369 char *term;
370 int malloc_size = 0; 370 ptrdiff_t malloc_size = 0;
371 register int c; 371 register int c;
372 char *tcenv = NULL; /* TERMCAP value, if it contains :tc=. */ 372 char *tcenv = NULL; /* TERMCAP value, if it contains :tc=. */
373 char *indirect = NULL; /* Terminal type in :tc= in TERMCAP value. */ 373 char *indirect = NULL; /* Terminal type in :tc= in TERMCAP value. */
@@ -637,6 +637,8 @@ gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end)
637 { 637 {
638 if (bufp->full == bufp->size) 638 if (bufp->full == bufp->size)
639 { 639 {
640 if ((PTRDIFF_MAX - 1) / 2 < bufp->size)
641 memory_full (SIZE_MAX);
640 bufp->size *= 2; 642 bufp->size *= 2;
641 /* Add 1 to size to ensure room for terminating null. */ 643 /* Add 1 to size to ensure room for terminating null. */
642 tem = (char *) xrealloc (buf, bufp->size + 1); 644 tem = (char *) xrealloc (buf, bufp->size + 1);
@@ -715,4 +717,3 @@ tprint (cap)
715} 717}
716 718
717#endif /* TEST */ 719#endif /* TEST */
718
diff --git a/src/textprop.c b/src/textprop.c
index 350892cdad6..dd8695f7af8 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -613,7 +613,7 @@ get_char_property_and_overlay (Lisp_Object position, register Lisp_Object prop,
613 } 613 }
614 if (BUFFERP (object)) 614 if (BUFFERP (object))
615 { 615 {
616 int noverlays; 616 ptrdiff_t noverlays;
617 Lisp_Object *overlay_vec; 617 Lisp_Object *overlay_vec;
618 struct buffer *obuf = current_buffer; 618 struct buffer *obuf = current_buffer;
619 619
diff --git a/src/w32term.h b/src/w32term.h
index cf6751b7d63..24a2be7dca9 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -103,7 +103,7 @@ struct w32_display_info
103 103
104 /* Emacs bitmap-id of the default icon bitmap for this frame. 104 /* Emacs bitmap-id of the default icon bitmap for this frame.
105 Or -1 if none has been allocated yet. */ 105 Or -1 if none has been allocated yet. */
106 int icon_bitmap_id; 106 ptrdiff_t icon_bitmap_id;
107 107
108 /* The root window of this screen. */ 108 /* The root window of this screen. */
109 Window root_window; 109 Window root_window;
@@ -151,10 +151,10 @@ struct w32_display_info
151 struct w32_bitmap_record *bitmaps; 151 struct w32_bitmap_record *bitmaps;
152 152
153 /* Allocated size of bitmaps field. */ 153 /* Allocated size of bitmaps field. */
154 int bitmaps_size; 154 ptrdiff_t bitmaps_size;
155 155
156 /* Last used bitmap index. */ 156 /* Last used bitmap index. */
157 int bitmaps_last; 157 ptrdiff_t bitmaps_last;
158 158
159 /* The frame (if any) which has the window that has keyboard focus. 159 /* The frame (if any) which has the window that has keyboard focus.
160 Zero if none. This is examined by Ffocus_frame in w32fns.c. Note 160 Zero if none. This is examined by Ffocus_frame in w32fns.c. Note
diff --git a/src/xdisp.c b/src/xdisp.c
index 3b34005d389..d04ceddacb2 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -810,7 +810,7 @@ static int cursor_row_fully_visible_p (struct window *, int, int);
810static int try_scrolling (Lisp_Object, int, EMACS_INT, EMACS_INT, int, int); 810static int try_scrolling (Lisp_Object, int, EMACS_INT, EMACS_INT, int, int);
811static int try_cursor_movement (Lisp_Object, struct text_pos, int *); 811static int try_cursor_movement (Lisp_Object, struct text_pos, int *);
812static int trailing_whitespace_p (EMACS_INT); 812static int trailing_whitespace_p (EMACS_INT);
813static unsigned long int message_log_check_duplicate (EMACS_INT, EMACS_INT); 813static intmax_t message_log_check_duplicate (EMACS_INT, EMACS_INT);
814static void push_it (struct it *, struct text_pos *); 814static void push_it (struct it *, struct text_pos *);
815static void pop_it (struct it *); 815static void pop_it (struct it *);
816static void sync_frame_with_window_matrix_rows (struct window *); 816static void sync_frame_with_window_matrix_rows (struct window *);
@@ -2384,7 +2384,7 @@ init_iterator (struct it *it, struct window *w,
2384 is invisible. >0 means lines indented more than this value are 2384 is invisible. >0 means lines indented more than this value are
2385 invisible. */ 2385 invisible. */
2386 it->selective = (INTEGERP (BVAR (current_buffer, selective_display)) 2386 it->selective = (INTEGERP (BVAR (current_buffer, selective_display))
2387 ? XFASTINT (BVAR (current_buffer, selective_display)) 2387 ? XINT (BVAR (current_buffer, selective_display))
2388 : (!NILP (BVAR (current_buffer, selective_display)) 2388 : (!NILP (BVAR (current_buffer, selective_display))
2389 ? -1 : 0)); 2389 ? -1 : 0));
2390 it->selective_display_ellipsis_p 2390 it->selective_display_ellipsis_p
@@ -3062,10 +3062,9 @@ compute_stop_pos (struct it *it)
3062static EMACS_INT 3062static EMACS_INT
3063next_overlay_change (EMACS_INT pos) 3063next_overlay_change (EMACS_INT pos)
3064{ 3064{
3065 int noverlays; 3065 ptrdiff_t i, noverlays;
3066 EMACS_INT endpos; 3066 EMACS_INT endpos;
3067 Lisp_Object *overlays; 3067 Lisp_Object *overlays;
3068 int i;
3069 3068
3070 /* Get all overlays at the given position. */ 3069 /* Get all overlays at the given position. */
3071 GET_OVERLAYS_AT (pos, overlays, noverlays, &endpos, 1); 3070 GET_OVERLAYS_AT (pos, overlays, noverlays, &endpos, 1);
@@ -5178,7 +5177,8 @@ back_to_previous_line_start (struct it *it)
5178static int 5177static int
5179forward_to_next_line_start (struct it *it, int *skipped_p) 5178forward_to_next_line_start (struct it *it, int *skipped_p)
5180{ 5179{
5181 int old_selective, newline_found_p, n; 5180 EMACS_INT old_selective;
5181 int newline_found_p, n;
5182 const int MAX_NEWLINE_DISTANCE = 500; 5182 const int MAX_NEWLINE_DISTANCE = 500;
5183 5183
5184 /* If already on a newline, just consume it to avoid unintended 5184 /* If already on a newline, just consume it to avoid unintended
@@ -5270,7 +5270,7 @@ back_to_previous_visible_line_start (struct it *it)
5270 invisible. */ 5270 invisible. */
5271 if (it->selective > 0 5271 if (it->selective > 0
5272 && indented_beyond_p (IT_CHARPOS (*it), IT_BYTEPOS (*it), 5272 && indented_beyond_p (IT_CHARPOS (*it), IT_BYTEPOS (*it),
5273 (double) it->selective)) /* iftc */ 5273 it->selective))
5274 continue; 5274 continue;
5275 5275
5276 /* Check the newline before point for invisibility. */ 5276 /* Check the newline before point for invisibility. */
@@ -5364,7 +5364,7 @@ reseat_at_next_visible_line_start (struct it *it, int on_newline_p)
5364 if (it->selective > 0) 5364 if (it->selective > 0)
5365 while (IT_CHARPOS (*it) < ZV 5365 while (IT_CHARPOS (*it) < ZV
5366 && indented_beyond_p (IT_CHARPOS (*it), IT_BYTEPOS (*it), 5366 && indented_beyond_p (IT_CHARPOS (*it), IT_BYTEPOS (*it),
5367 (double) it->selective)) /* iftc */ 5367 it->selective))
5368 { 5368 {
5369 xassert (IT_BYTEPOS (*it) == BEGV 5369 xassert (IT_BYTEPOS (*it) == BEGV
5370 || FETCH_BYTE (IT_BYTEPOS (*it) - 1) == '\n'); 5370 || FETCH_BYTE (IT_BYTEPOS (*it) - 1) == '\n');
@@ -6812,7 +6812,7 @@ next_element_from_buffer (struct it *it)
6812 && IT_CHARPOS (*it) + 1 < ZV 6812 && IT_CHARPOS (*it) + 1 < ZV
6813 && indented_beyond_p (IT_CHARPOS (*it) + 1, 6813 && indented_beyond_p (IT_CHARPOS (*it) + 1,
6814 IT_BYTEPOS (*it) + 1, 6814 IT_BYTEPOS (*it) + 1,
6815 (double) it->selective)) /* iftc */ 6815 it->selective))
6816 { 6816 {
6817 success_p = next_element_from_ellipsis (it); 6817 success_p = next_element_from_ellipsis (it);
6818 it->dpvec_char_len = -1; 6818 it->dpvec_char_len = -1;
@@ -8063,7 +8063,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
8063 if (nlflag) 8063 if (nlflag)
8064 { 8064 {
8065 EMACS_INT this_bol, this_bol_byte, prev_bol, prev_bol_byte; 8065 EMACS_INT this_bol, this_bol_byte, prev_bol, prev_bol_byte;
8066 unsigned long int dups; 8066 intmax_t dups;
8067 insert_1 ("\n", 1, 1, 0, 0); 8067 insert_1 ("\n", 1, 1, 0, 0);
8068 8068
8069 scan_newline (Z, Z_BYTE, BEG, BEG_BYTE, -2, 0); 8069 scan_newline (Z, Z_BYTE, BEG, BEG_BYTE, -2, 0);
@@ -8086,12 +8086,13 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
8086 this_bol, this_bol_byte, 0); 8086 this_bol, this_bol_byte, 0);
8087 if (dups > 1) 8087 if (dups > 1)
8088 { 8088 {
8089 char dupstr[40]; 8089 char dupstr[sizeof " [ times]"
8090 + INT_STRLEN_BOUND (intmax_t)];
8090 int duplen; 8091 int duplen;
8091 8092
8092 /* If you change this format, don't forget to also 8093 /* If you change this format, don't forget to also
8093 change message_log_check_duplicate. */ 8094 change message_log_check_duplicate. */
8094 sprintf (dupstr, " [%lu times]", dups); 8095 sprintf (dupstr, " [%"PRIdMAX" times]", dups);
8095 duplen = strlen (dupstr); 8096 duplen = strlen (dupstr);
8096 TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1); 8097 TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1);
8097 insert_1 (dupstr, duplen, 1, 0, 1); 8098 insert_1 (dupstr, duplen, 1, 0, 1);
@@ -8153,7 +8154,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte)
8153 Return 0 if different, 1 if the new one should just replace it, or a 8154 Return 0 if different, 1 if the new one should just replace it, or a
8154 value N > 1 if we should also append " [N times]". */ 8155 value N > 1 if we should also append " [N times]". */
8155 8156
8156static unsigned long int 8157static intmax_t
8157message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte) 8158message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte)
8158{ 8159{
8159 EMACS_INT i; 8160 EMACS_INT i;
@@ -8175,8 +8176,8 @@ message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte)
8175 if (*p1++ == ' ' && *p1++ == '[') 8176 if (*p1++ == ' ' && *p1++ == '[')
8176 { 8177 {
8177 char *pend; 8178 char *pend;
8178 unsigned long int n = strtoul ((char *) p1, &pend, 10); 8179 intmax_t n = strtoimax ((char *) p1, &pend, 10);
8179 if (strncmp (pend, " times]\n", 8) == 0) 8180 if (0 < n && n < INTMAX_MAX && strncmp (pend, " times]\n", 8) == 0)
8180 return n+1; 8181 return n+1;
8181 } 8182 }
8182 return 0; 8183 return 0;
@@ -18728,8 +18729,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
18728 break; 18729 break;
18729 case MODE_LINE_STRING: 18730 case MODE_LINE_STRING:
18730 { 18731 {
18731 int len = strlen (spec); 18732 Lisp_Object tem = build_string (spec);
18732 Lisp_Object tem = make_string (spec, len);
18733 props = Ftext_properties_at (make_number (charpos), elt); 18733 props = Ftext_properties_at (make_number (charpos), elt);
18734 /* Should only keep face property in props */ 18734 /* Should only keep face property in props */
18735 n += store_mode_line_string (NULL, tem, 0, field, prec, props); 18735 n += store_mode_line_string (NULL, tem, 0, field, prec, props);
@@ -25452,13 +25452,13 @@ note_mouse_highlight (struct frame *f, int x, int y)
25452 && XFASTINT (w->last_modified) == BUF_MODIFF (b) 25452 && XFASTINT (w->last_modified) == BUF_MODIFF (b)
25453 && XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b)) 25453 && XFASTINT (w->last_overlay_modified) == BUF_OVERLAY_MODIFF (b))
25454 { 25454 {
25455 int hpos, vpos, i, dx, dy, area; 25455 int hpos, vpos, dx, dy, area;
25456 EMACS_INT pos; 25456 EMACS_INT pos;
25457 struct glyph *glyph; 25457 struct glyph *glyph;
25458 Lisp_Object object; 25458 Lisp_Object object;
25459 Lisp_Object mouse_face = Qnil, position; 25459 Lisp_Object mouse_face = Qnil, position;
25460 Lisp_Object *overlay_vec = NULL; 25460 Lisp_Object *overlay_vec = NULL;
25461 int noverlays; 25461 ptrdiff_t i, noverlays;
25462 struct buffer *obuf; 25462 struct buffer *obuf;
25463 EMACS_INT obegv, ozv; 25463 EMACS_INT obegv, ozv;
25464 int same_region; 25464 int same_region;
diff --git a/src/xfaces.c b/src/xfaces.c
index 78ea913526e..99c35fbb120 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -463,7 +463,8 @@ static Lisp_Object resolve_face_name (Lisp_Object, int);
463static void set_font_frame_param (Lisp_Object, Lisp_Object); 463static void set_font_frame_param (Lisp_Object, Lisp_Object);
464static int get_lface_attributes (struct frame *, Lisp_Object, Lisp_Object *, 464static int get_lface_attributes (struct frame *, Lisp_Object, Lisp_Object *,
465 int, struct named_merge_point *); 465 int, struct named_merge_point *);
466static int load_pixmap (struct frame *, Lisp_Object, unsigned *, unsigned *); 466static ptrdiff_t load_pixmap (struct frame *, Lisp_Object,
467 unsigned *, unsigned *);
467static struct frame *frame_or_selected_frame (Lisp_Object, int); 468static struct frame *frame_or_selected_frame (Lisp_Object, int);
468static void load_face_colors (struct frame *, struct face *, Lisp_Object *); 469static void load_face_colors (struct frame *, struct face *, Lisp_Object *);
469static void free_face_colors (struct frame *, struct face *); 470static void free_face_colors (struct frame *, struct face *);
@@ -963,10 +964,10 @@ the pixmap. Bits are stored row by row, each row occupies
963 zero. Store the bitmap width in *W_PTR and its height in *H_PTR, 964 zero. Store the bitmap width in *W_PTR and its height in *H_PTR,
964 if these pointers are not null. */ 965 if these pointers are not null. */
965 966
966static int 967static ptrdiff_t
967load_pixmap (FRAME_PTR f, Lisp_Object name, unsigned int *w_ptr, unsigned int *h_ptr) 968load_pixmap (FRAME_PTR f, Lisp_Object name, unsigned int *w_ptr, unsigned int *h_ptr)
968{ 969{
969 int bitmap_id; 970 ptrdiff_t bitmap_id;
970 971
971 if (NILP (name)) 972 if (NILP (name))
972 return 0; 973 return 0;
@@ -5934,7 +5935,7 @@ face_at_buffer_position (struct window *w, EMACS_INT pos,
5934 struct frame *f = XFRAME (w->frame); 5935 struct frame *f = XFRAME (w->frame);
5935 Lisp_Object attrs[LFACE_VECTOR_SIZE]; 5936 Lisp_Object attrs[LFACE_VECTOR_SIZE];
5936 Lisp_Object prop, position; 5937 Lisp_Object prop, position;
5937 int i, noverlays; 5938 ptrdiff_t i, noverlays;
5938 Lisp_Object *overlay_vec; 5939 Lisp_Object *overlay_vec;
5939 Lisp_Object frame; 5940 Lisp_Object frame;
5940 EMACS_INT endpos; 5941 EMACS_INT endpos;
diff --git a/src/xfns.c b/src/xfns.c
index 20bfa1df3f0..e98e287f50b 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1883,7 +1883,7 @@ xic_create_fontsetname (const char *base_fontname, int motif)
1883 /* Make a fontset name from the base font name. */ 1883 /* Make a fontset name from the base font name. */
1884 if (xic_defaut_fontset == base_fontname) 1884 if (xic_defaut_fontset == base_fontname)
1885 { /* There is no base font name, use the default. */ 1885 { /* There is no base font name, use the default. */
1886 int len = strlen (base_fontname) + 2; 1886 ptrdiff_t len = strlen (base_fontname) + 2;
1887 fontsetname = xmalloc (len); 1887 fontsetname = xmalloc (len);
1888 memset (fontsetname, 0, len); 1888 memset (fontsetname, 0, len);
1889 strcpy (fontsetname, base_fontname); 1889 strcpy (fontsetname, base_fontname);
@@ -1896,7 +1896,7 @@ xic_create_fontsetname (const char *base_fontname, int motif)
1896 - the base font where the charset spec is replaced by -*-*. 1896 - the base font where the charset spec is replaced by -*-*.
1897 - the same but with the family also replaced with -*-*-. */ 1897 - the same but with the family also replaced with -*-*-. */
1898 const char *p = base_fontname; 1898 const char *p = base_fontname;
1899 int i; 1899 ptrdiff_t i;
1900 1900
1901 for (i = 0; *p; p++) 1901 for (i = 0; *p; p++)
1902 if (*p == '-') i++; 1902 if (*p == '-') i++;
@@ -1904,7 +1904,8 @@ xic_create_fontsetname (const char *base_fontname, int motif)
1904 { /* As the font name doesn't conform to XLFD, we can't 1904 { /* As the font name doesn't conform to XLFD, we can't
1905 modify it to generalize it to allcs and allfamilies. 1905 modify it to generalize it to allcs and allfamilies.
1906 Use the specified font plus the default. */ 1906 Use the specified font plus the default. */
1907 int len = strlen (base_fontname) + strlen (xic_defaut_fontset) + 3; 1907 ptrdiff_t len =
1908 strlen (base_fontname) + strlen (xic_defaut_fontset) + 3;
1908 fontsetname = xmalloc (len); 1909 fontsetname = xmalloc (len);
1909 memset (fontsetname, 0, len); 1910 memset (fontsetname, 0, len);
1910 strcpy (fontsetname, base_fontname); 1911 strcpy (fontsetname, base_fontname);
@@ -1913,7 +1914,7 @@ xic_create_fontsetname (const char *base_fontname, int motif)
1913 } 1914 }
1914 else 1915 else
1915 { 1916 {
1916 int len; 1917 ptrdiff_t len;
1917 const char *p1 = NULL, *p2 = NULL, *p3 = NULL; 1918 const char *p1 = NULL, *p2 = NULL, *p3 = NULL;
1918 char *font_allcs = NULL; 1919 char *font_allcs = NULL;
1919 char *font_allfamilies = NULL; 1920 char *font_allfamilies = NULL;
@@ -1940,7 +1941,7 @@ xic_create_fontsetname (const char *base_fontname, int motif)
1940 wildcard. */ 1941 wildcard. */
1941 if (*p3 != '*') 1942 if (*p3 != '*')
1942 { 1943 {
1943 int diff = (p2 - p3) - 2; 1944 ptrdiff_t diff = (p2 - p3) - 2;
1944 1945
1945 base = alloca (strlen (base_fontname) + 1); 1946 base = alloca (strlen (base_fontname) + 1);
1946 memcpy (base, base_fontname, p3 - base_fontname); 1947 memcpy (base, base_fontname, p3 - base_fontname);
@@ -2434,7 +2435,7 @@ x_window (struct frame *f, long window_prompting, int minibuffer_only)
2434 2435
2435 /* Do some needed geometry management. */ 2436 /* Do some needed geometry management. */
2436 { 2437 {
2437 int len; 2438 ptrdiff_t len;
2438 char *tem, shell_position[32]; 2439 char *tem, shell_position[32];
2439 Arg gal[10]; 2440 Arg gal[10];
2440 int gac = 0; 2441 int gac = 0;
diff --git a/src/xfont.c b/src/xfont.c
index 5dd6aae3846..2c3ca911623 100644
--- a/src/xfont.c
+++ b/src/xfont.c
@@ -594,16 +594,14 @@ xfont_match (Lisp_Object frame, Lisp_Object spec)
594 { 594 {
595 if (XGetFontProperty (xfont, XA_FONT, &value)) 595 if (XGetFontProperty (xfont, XA_FONT, &value))
596 { 596 {
597 int len;
598 char *s; 597 char *s;
599 598
600 s = (char *) XGetAtomName (display, (Atom) value); 599 s = (char *) XGetAtomName (display, (Atom) value);
601 len = strlen (s);
602 600
603 /* If DXPC (a Differential X Protocol Compressor) 601 /* If DXPC (a Differential X Protocol Compressor)
604 Ver.3.7 is running, XGetAtomName will return null 602 Ver.3.7 is running, XGetAtomName will return null
605 string. We must avoid such a name. */ 603 string. We must avoid such a name. */
606 if (len > 0) 604 if (*s)
607 { 605 {
608 entity = font_make_entity (); 606 entity = font_make_entity ();
609 ASET (entity, FONT_TYPE_INDEX, Qx); 607 ASET (entity, FONT_TYPE_INDEX, Qx);
diff --git a/src/xrdb.c b/src/xrdb.c
index b490afdabaa..e18ff65f799 100644
--- a/src/xrdb.c
+++ b/src/xrdb.c
@@ -120,20 +120,20 @@ x_get_customization_string (XrmDatabase db, const char *name,
120 refers to %L only when the LANG environment variable is set, or 120 refers to %L only when the LANG environment variable is set, or
121 otherwise provided by X. 121 otherwise provided by X.
122 122
123 ESCAPED_SUFFIX and SUFFIX are postpended to STRING if they are 123 ESCAPED_SUFFIX is postpended to STRING if it is non-zero.
124 non-zero. %-escapes in ESCAPED_SUFFIX are expanded; STRING is left 124 %-escapes in ESCAPED_SUFFIX are expanded.
125 alone.
126 125
127 Return NULL otherwise. */ 126 Return NULL otherwise. */
128 127
129static char * 128static char *
130magic_file_p (const char *string, EMACS_INT string_len, const char *class, const char *escaped_suffix, const char *suffix) 129magic_file_p (const char *string, EMACS_INT string_len, const char *class,
130 const char *escaped_suffix)
131{ 131{
132 char *lang = getenv ("LANG"); 132 char *lang = getenv ("LANG");
133 133
134 int path_size = 100; 134 ptrdiff_t path_size = 100;
135 char *path = (char *) xmalloc (path_size); 135 char *path = (char *) xmalloc (path_size);
136 int path_len = 0; 136 ptrdiff_t path_len = 0;
137 137
138 const char *p = string; 138 const char *p = string;
139 139
@@ -141,7 +141,7 @@ magic_file_p (const char *string, EMACS_INT string_len, const char *class, const
141 { 141 {
142 /* The chunk we're about to stick on the end of result. */ 142 /* The chunk we're about to stick on the end of result. */
143 const char *next = NULL; 143 const char *next = NULL;
144 int next_len; 144 ptrdiff_t next_len;
145 145
146 if (*p == '%') 146 if (*p == '%')
147 { 147 {
@@ -201,8 +201,10 @@ magic_file_p (const char *string, EMACS_INT string_len, const char *class, const
201 next = p, next_len = 1; 201 next = p, next_len = 1;
202 202
203 /* Do we have room for this component followed by a '\0' ? */ 203 /* Do we have room for this component followed by a '\0' ? */
204 if (path_len + next_len + 1 > path_size) 204 if (path_size - path_len <= next_len)
205 { 205 {
206 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 - 1 - path_len < next_len)
207 memory_full (SIZE_MAX);
206 path_size = (path_len + next_len + 1) * 2; 208 path_size = (path_len + next_len + 1) * 2;
207 path = (char *) xrealloc (path, path_size); 209 path = (char *) xrealloc (path, path_size);
208 } 210 }
@@ -222,21 +224,6 @@ magic_file_p (const char *string, EMACS_INT string_len, const char *class, const
222 } 224 }
223 } 225 }
224 226
225 /* Perhaps we should add the SUFFIX now. */
226 if (suffix)
227 {
228 int suffix_len = strlen (suffix);
229
230 if (path_len + suffix_len + 1 > path_size)
231 {
232 path_size = (path_len + suffix_len + 1);
233 path = (char *) xrealloc (path, path_size);
234 }
235
236 memcpy (path + path_len, suffix, suffix_len);
237 path_len += suffix_len;
238 }
239
240 path[path_len] = '\0'; 227 path[path_len] = '\0';
241 228
242 if (! file_p (path)) 229 if (! file_p (path))
@@ -295,7 +282,8 @@ file_p (const char *filename)
295 the path name of the one we found otherwise. */ 282 the path name of the one we found otherwise. */
296 283
297static char * 284static char *
298search_magic_path (const char *search_path, const char *class, const char *escaped_suffix, const char *suffix) 285search_magic_path (const char *search_path, const char *class,
286 const char *escaped_suffix)
299{ 287{
300 const char *s, *p; 288 const char *s, *p;
301 289
@@ -306,8 +294,7 @@ search_magic_path (const char *search_path, const char *class, const char *escap
306 294
307 if (p > s) 295 if (p > s)
308 { 296 {
309 char *path = magic_file_p (s, p - s, class, escaped_suffix, 297 char *path = magic_file_p (s, p - s, class, escaped_suffix);
310 suffix);
311 if (path) 298 if (path)
312 return path; 299 return path;
313 } 300 }
@@ -316,7 +303,7 @@ search_magic_path (const char *search_path, const char *class, const char *escap
316 char *path; 303 char *path;
317 304
318 s = "%N%S"; 305 s = "%N%S";
319 path = magic_file_p (s, strlen (s), class, escaped_suffix, suffix); 306 path = magic_file_p (s, strlen (s), class, escaped_suffix);
320 if (path) 307 if (path)
321 return path; 308 return path;
322 } 309 }
@@ -340,7 +327,7 @@ get_system_app (const char *class)
340 path = getenv ("XFILESEARCHPATH"); 327 path = getenv ("XFILESEARCHPATH");
341 if (! path) path = PATH_X_DEFAULTS; 328 if (! path) path = PATH_X_DEFAULTS;
342 329
343 p = search_magic_path (path, class, 0, 0); 330 p = search_magic_path (path, class, 0);
344 if (p) 331 if (p)
345 { 332 {
346 db = XrmGetFileDatabase (p); 333 db = XrmGetFileDatabase (p);
@@ -368,19 +355,19 @@ get_user_app (const char *class)
368 /* Check for XUSERFILESEARCHPATH. It is a path of complete file 355 /* Check for XUSERFILESEARCHPATH. It is a path of complete file
369 names, not directories. */ 356 names, not directories. */
370 if (((path = getenv ("XUSERFILESEARCHPATH")) 357 if (((path = getenv ("XUSERFILESEARCHPATH"))
371 && (file = search_magic_path (path, class, 0, 0))) 358 && (file = search_magic_path (path, class, 0)))
372 359
373 /* Check for APPLRESDIR; it is a path of directories. In each, 360 /* Check for APPLRESDIR; it is a path of directories. In each,
374 we have to search for LANG/CLASS and then CLASS. */ 361 we have to search for LANG/CLASS and then CLASS. */
375 || ((path = getenv ("XAPPLRESDIR")) 362 || ((path = getenv ("XAPPLRESDIR"))
376 && ((file = search_magic_path (path, class, "/%L/%N", 0)) 363 && ((file = search_magic_path (path, class, "/%L/%N"))
377 || (file = search_magic_path (path, class, "/%N", 0)))) 364 || (file = search_magic_path (path, class, "/%N"))))
378 365
379 /* Check in the home directory. This is a bit of a hack; let's 366 /* Check in the home directory. This is a bit of a hack; let's
380 hope one's home directory doesn't contain any %-escapes. */ 367 hope one's home directory doesn't contain any %-escapes. */
381 || (free_it = gethomedir (), 368 || (free_it = gethomedir (),
382 ((file = search_magic_path (free_it, class, "%L/%N", 0)) 369 ((file = search_magic_path (free_it, class, "%L/%N"))
383 || (file = search_magic_path (free_it, class, "%N", 0))))) 370 || (file = search_magic_path (free_it, class, "%N")))))
384 { 371 {
385 XrmDatabase db = XrmGetFileDatabase (file); 372 XrmDatabase db = XrmGetFileDatabase (file);
386 xfree (file); 373 xfree (file);
diff --git a/src/xselect.c b/src/xselect.c
index 5b01fc22a42..7f4e0b40f62 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -2361,7 +2361,7 @@ If the value is 0 or the atom is not known, return the empty string. */)
2361 x_uncatch_errors (); 2361 x_uncatch_errors ();
2362 2362
2363 if (!had_errors) 2363 if (!had_errors)
2364 ret = make_string (name, strlen (name)); 2364 ret = build_string (name);
2365 2365
2366 if (atom && name) XFree (name); 2366 if (atom && name) XFree (name);
2367 if (NILP (ret)) ret = empty_unibyte_string; 2367 if (NILP (ret)) ret = empty_unibyte_string;
diff --git a/src/xsettings.c b/src/xsettings.c
index 2513bcc5aa8..e2575650df9 100644
--- a/src/xsettings.c
+++ b/src/xsettings.c
@@ -18,6 +18,8 @@ You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 19
20#include <config.h> 20#include <config.h>
21
22#include <float.h>
21#include <limits.h> 23#include <limits.h>
22#include <setjmp.h> 24#include <setjmp.h>
23#include <fcntl.h> 25#include <fcntl.h>
@@ -434,10 +436,8 @@ apply_xft_settings (struct x_display_info *dpyinfo,
434 FcPattern *pat; 436 FcPattern *pat;
435 struct xsettings oldsettings; 437 struct xsettings oldsettings;
436 int changed = 0; 438 int changed = 0;
437 char buf[256];
438 439
439 memset (&oldsettings, 0, sizeof (oldsettings)); 440 memset (&oldsettings, 0, sizeof (oldsettings));
440 buf[0] = '\0';
441 pat = FcPatternCreate (); 441 pat = FcPatternCreate ();
442 XftDefaultSubstitute (dpyinfo->display, 442 XftDefaultSubstitute (dpyinfo->display,
443 XScreenNumberOfScreen (dpyinfo->screen), 443 XScreenNumberOfScreen (dpyinfo->screen),
@@ -458,7 +458,6 @@ apply_xft_settings (struct x_display_info *dpyinfo,
458 ++changed; 458 ++changed;
459 oldsettings.aa = settings->aa; 459 oldsettings.aa = settings->aa;
460 } 460 }
461 sprintf (buf, "Antialias: %d", oldsettings.aa);
462 461
463 if ((settings->seen & SEEN_HINTING) != 0 462 if ((settings->seen & SEEN_HINTING) != 0
464 && oldsettings.hinting != settings->hinting) 463 && oldsettings.hinting != settings->hinting)
@@ -468,8 +467,6 @@ apply_xft_settings (struct x_display_info *dpyinfo,
468 ++changed; 467 ++changed;
469 oldsettings.hinting = settings->hinting; 468 oldsettings.hinting = settings->hinting;
470 } 469 }
471 if (strlen (buf) > 0) strcat (buf, ", ");
472 sprintf (buf+strlen (buf), "Hinting: %d", oldsettings.hinting);
473 if ((settings->seen & SEEN_RGBA) != 0 && oldsettings.rgba != settings->rgba) 470 if ((settings->seen & SEEN_RGBA) != 0 && oldsettings.rgba != settings->rgba)
474 { 471 {
475 FcPatternDel (pat, FC_RGBA); 472 FcPatternDel (pat, FC_RGBA);
@@ -477,8 +474,6 @@ apply_xft_settings (struct x_display_info *dpyinfo,
477 oldsettings.rgba = settings->rgba; 474 oldsettings.rgba = settings->rgba;
478 ++changed; 475 ++changed;
479 } 476 }
480 if (strlen (buf) > 0) strcat (buf, ", ");
481 sprintf (buf+strlen (buf), "RGBA: %d", oldsettings.rgba);
482 477
483 /* Older fontconfig versions don't have FC_LCD_FILTER. */ 478 /* Older fontconfig versions don't have FC_LCD_FILTER. */
484 if ((settings->seen & SEEN_LCDFILTER) != 0 479 if ((settings->seen & SEEN_LCDFILTER) != 0
@@ -489,8 +484,6 @@ apply_xft_settings (struct x_display_info *dpyinfo,
489 ++changed; 484 ++changed;
490 oldsettings.lcdfilter = settings->lcdfilter; 485 oldsettings.lcdfilter = settings->lcdfilter;
491 } 486 }
492 if (strlen (buf) > 0) strcat (buf, ", ");
493 sprintf (buf+strlen (buf), "LCDFilter: %d", oldsettings.lcdfilter);
494 487
495# ifdef FC_HINT_STYLE 488# ifdef FC_HINT_STYLE
496 if ((settings->seen & SEEN_HINTSTYLE) != 0 489 if ((settings->seen & SEEN_HINTSTYLE) != 0
@@ -502,8 +495,6 @@ apply_xft_settings (struct x_display_info *dpyinfo,
502 oldsettings.hintstyle = settings->hintstyle; 495 oldsettings.hintstyle = settings->hintstyle;
503 } 496 }
504# endif 497# endif
505 if (strlen (buf) > 0) strcat (buf, ", ");
506 sprintf (buf+strlen (buf), "Hintstyle: %d", oldsettings.hintstyle);
507 498
508 if ((settings->seen & SEEN_DPI) != 0 && oldsettings.dpi != settings->dpi 499 if ((settings->seen & SEEN_DPI) != 0 && oldsettings.dpi != settings->dpi
509 && settings->dpi > 0) 500 && settings->dpi > 0)
@@ -523,16 +514,31 @@ apply_xft_settings (struct x_display_info *dpyinfo,
523 XFRAME (frame)->resy = XFRAME (frame)->resx = settings->dpi; 514 XFRAME (frame)->resy = XFRAME (frame)->resx = settings->dpi;
524 } 515 }
525 516
526 if (strlen (buf) > 0) strcat (buf, ", ");
527 sprintf (buf+strlen (buf), "DPI: %lf", oldsettings.dpi);
528
529 if (changed) 517 if (changed)
530 { 518 {
519 static char const format[] =
520 "Antialias: %d, Hinting: %d, RGBA: %d, LCDFilter: %d, "
521 "Hintstyle: %d, DPI: %lf";
522 enum
523 {
524 d_formats = 5,
525 d_growth = INT_BUFSIZE_BOUND (int) - sizeof "%d",
526 lf_formats = 1,
527 max_f_integer_digits = DBL_MAX_10_EXP + 1,
528 f_precision = 6,
529 lf_growth = (sizeof "-." + max_f_integer_digits + f_precision
530 - sizeof "%lf")
531 };
532 char buf[sizeof format + d_formats * d_growth + lf_formats * lf_growth];
533
531 XftDefaultSet (dpyinfo->display, pat); 534 XftDefaultSet (dpyinfo->display, pat);
532 if (send_event_p) 535 if (send_event_p)
533 store_config_changed_event (Qfont_render, 536 store_config_changed_event (Qfont_render,
534 XCAR (dpyinfo->name_list_element)); 537 XCAR (dpyinfo->name_list_element));
535 Vxft_settings = make_string (buf, strlen (buf)); 538 sprintf (buf, format, oldsettings.aa, oldsettings.hinting,
539 oldsettings.rgba, oldsettings.lcdfilter,
540 oldsettings.hintstyle, oldsettings.dpi);
541 Vxft_settings = build_string (buf);
536 } 542 }
537 else 543 else
538 FcPatternDestroy (pat); 544 FcPatternDestroy (pat);
@@ -705,9 +711,7 @@ DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font,
705 doc: /* Get the system default application font. */) 711 doc: /* Get the system default application font. */)
706 (void) 712 (void)
707{ 713{
708 return current_font 714 return current_font ? build_string (current_font) : Qnil;
709 ? make_string (current_font, strlen (current_font))
710 : Qnil;
711} 715}
712 716
713DEFUN ("font-get-system-font", Ffont_get_system_font, Sfont_get_system_font, 717DEFUN ("font-get-system-font", Ffont_get_system_font, Sfont_get_system_font,
@@ -715,9 +719,7 @@ DEFUN ("font-get-system-font", Ffont_get_system_font, Sfont_get_system_font,
715 doc: /* Get the system default fixed width font. */) 719 doc: /* Get the system default fixed width font. */)
716 (void) 720 (void)
717{ 721{
718 return current_mono_font 722 return current_mono_font ? build_string (current_mono_font) : Qnil;
719 ? make_string (current_mono_font, strlen (current_mono_font))
720 : Qnil;
721} 723}
722 724
723DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style, 725DEFUN ("tool-bar-get-system-style", Ftool_bar_get_system_style,
diff --git a/src/xsmfns.c b/src/xsmfns.c
index c199036587f..cb56ae648d1 100644
--- a/src/xsmfns.c
+++ b/src/xsmfns.c
@@ -190,7 +190,7 @@ smc_save_yourself_CB (SmcConn smcConn,
190 props[props_idx]->type = xstrdup (SmARRAY8); 190 props[props_idx]->type = xstrdup (SmARRAY8);
191 props[props_idx]->num_vals = 1; 191 props[props_idx]->num_vals = 1;
192 props[props_idx]->vals = &values[val_idx++]; 192 props[props_idx]->vals = &values[val_idx++];
193 props[props_idx]->vals[0].length = strlen (SSDATA (Vinvocation_name)); 193 props[props_idx]->vals[0].length = SBYTES (Vinvocation_name);
194 props[props_idx]->vals[0].value = SDATA (Vinvocation_name); 194 props[props_idx]->vals[0].value = SDATA (Vinvocation_name);
195 ++props_idx; 195 ++props_idx;
196 196
@@ -200,7 +200,7 @@ smc_save_yourself_CB (SmcConn smcConn,
200 props[props_idx]->type = xstrdup (SmARRAY8); 200 props[props_idx]->type = xstrdup (SmARRAY8);
201 props[props_idx]->num_vals = 1; 201 props[props_idx]->num_vals = 1;
202 props[props_idx]->vals = &values[val_idx++]; 202 props[props_idx]->vals = &values[val_idx++];
203 props[props_idx]->vals[0].length = strlen (SSDATA (Vuser_login_name)); 203 props[props_idx]->vals[0].length = SBYTES (Vuser_login_name);
204 props[props_idx]->vals[0].value = SDATA (Vuser_login_name); 204 props[props_idx]->vals[0].value = SDATA (Vuser_login_name);
205 ++props_idx; 205 ++props_idx;
206 206
@@ -398,7 +398,7 @@ x_session_initialize (struct x_display_info *dpyinfo)
398 char errorstring[SM_ERRORSTRING_LEN]; 398 char errorstring[SM_ERRORSTRING_LEN];
399 char* previous_id = NULL; 399 char* previous_id = NULL;
400 SmcCallbacks callbacks; 400 SmcCallbacks callbacks;
401 int name_len = 0; 401 ptrdiff_t name_len = 0;
402 402
403 ice_fd = -1; 403 ice_fd = -1;
404 doing_interact = False; 404 doing_interact = False;
@@ -410,8 +410,8 @@ x_session_initialize (struct x_display_info *dpyinfo)
410 410
411 /* Construct the path to the Emacs program. */ 411 /* Construct the path to the Emacs program. */
412 if (! EQ (Vinvocation_directory, Qnil)) 412 if (! EQ (Vinvocation_directory, Qnil))
413 name_len += strlen (SSDATA (Vinvocation_directory)); 413 name_len += SBYTES (Vinvocation_directory);
414 name_len += strlen (SSDATA (Vinvocation_name)); 414 name_len += SBYTES (Vinvocation_name);
415 415
416 /* This malloc will not be freed, but it is only done once, and hopefully 416 /* This malloc will not be freed, but it is only done once, and hopefully
417 not very large */ 417 not very large */
@@ -457,7 +457,7 @@ x_session_initialize (struct x_display_info *dpyinfo)
457 457
458 if (smc_conn != 0) 458 if (smc_conn != 0)
459 { 459 {
460 Vx_session_id = make_string (client_id, strlen (client_id)); 460 Vx_session_id = build_string (client_id);
461 461
462#ifdef USE_GTK 462#ifdef USE_GTK
463 /* GTK creats a leader window by itself, but we need to tell 463 /* GTK creats a leader window by itself, but we need to tell
diff --git a/src/xterm.c b/src/xterm.c
index f40d260dabe..32fbab55008 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -356,7 +356,7 @@ static int x_dispatch_event (XEvent *, Display *);
356 interference with debugging failing X calls. */ 356 interference with debugging failing X calls. */
357static void x_connection_closed (Display *, const char *); 357static void x_connection_closed (Display *, const char *);
358static void x_wm_set_window_state (struct frame *, int); 358static void x_wm_set_window_state (struct frame *, int);
359static void x_wm_set_icon_pixmap (struct frame *, int); 359static void x_wm_set_icon_pixmap (struct frame *, ptrdiff_t);
360static void x_initialize (void); 360static void x_initialize (void);
361 361
362 362
@@ -7427,7 +7427,7 @@ x_draw_window_cursor (struct window *w, struct glyph_row *glyph_row, int x, int
7427int 7427int
7428x_bitmap_icon (struct frame *f, Lisp_Object file) 7428x_bitmap_icon (struct frame *f, Lisp_Object file)
7429{ 7429{
7430 int bitmap_id; 7430 ptrdiff_t bitmap_id;
7431 7431
7432 if (FRAME_X_WINDOW (f) == 0) 7432 if (FRAME_X_WINDOW (f) == 0)
7433 return 1; 7433 return 1;
@@ -7453,7 +7453,7 @@ x_bitmap_icon (struct frame *f, Lisp_Object file)
7453 /* Create the GNU bitmap and mask if necessary. */ 7453 /* Create the GNU bitmap and mask if necessary. */
7454 if (FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id < 0) 7454 if (FRAME_X_DISPLAY_INFO (f)->icon_bitmap_id < 0)
7455 { 7455 {
7456 int rc = -1; 7456 ptrdiff_t rc = -1;
7457 7457
7458#ifdef USE_GTK 7458#ifdef USE_GTK
7459 7459
@@ -8084,7 +8084,7 @@ xim_initialize (struct x_display_info *dpyinfo, char *resource_name)
8084 { 8084 {
8085#ifdef HAVE_X11R6_XIM 8085#ifdef HAVE_X11R6_XIM
8086 struct xim_inst_t *xim_inst; 8086 struct xim_inst_t *xim_inst;
8087 int len; 8087 ptrdiff_t len;
8088 8088
8089 xim_inst = (struct xim_inst_t *) xmalloc (sizeof (struct xim_inst_t)); 8089 xim_inst = (struct xim_inst_t *) xmalloc (sizeof (struct xim_inst_t));
8090 dpyinfo->xim_callback_data = xim_inst; 8090 dpyinfo->xim_callback_data = xim_inst;
@@ -9601,7 +9601,7 @@ x_wm_set_window_state (struct frame *f, int state)
9601} 9601}
9602 9602
9603static void 9603static void
9604x_wm_set_icon_pixmap (struct frame *f, int pixmap_id) 9604x_wm_set_icon_pixmap (struct frame *f, ptrdiff_t pixmap_id)
9605{ 9605{
9606 Pixmap icon_pixmap, icon_mask; 9606 Pixmap icon_pixmap, icon_mask;
9607 9607
@@ -9720,8 +9720,8 @@ same_x_server (const char *name1, const char *name2)
9720{ 9720{
9721 int seen_colon = 0; 9721 int seen_colon = 0;
9722 const char *system_name = SSDATA (Vsystem_name); 9722 const char *system_name = SSDATA (Vsystem_name);
9723 int system_name_length = strlen (system_name); 9723 ptrdiff_t system_name_length = SBYTES (Vsystem_name);
9724 int length_until_period = 0; 9724 ptrdiff_t length_until_period = 0;
9725 9725
9726 while (system_name[length_until_period] != 0 9726 while (system_name[length_until_period] != 0
9727 && system_name[length_until_period] != '.') 9727 && system_name[length_until_period] != '.')
diff --git a/src/xterm.h b/src/xterm.h
index 47d7e533769..a4767361bb3 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -158,7 +158,7 @@ struct x_display_info
158 158
159 /* Emacs bitmap-id of the default icon bitmap for this frame. 159 /* Emacs bitmap-id of the default icon bitmap for this frame.
160 Or -1 if none has been allocated yet. */ 160 Or -1 if none has been allocated yet. */
161 int icon_bitmap_id; 161 ptrdiff_t icon_bitmap_id;
162 162
163 /* The root window of this screen. */ 163 /* The root window of this screen. */
164 Window root_window; 164 Window root_window;
@@ -202,10 +202,10 @@ struct x_display_info
202 struct x_bitmap_record *bitmaps; 202 struct x_bitmap_record *bitmaps;
203 203
204 /* Allocated size of bitmaps field. */ 204 /* Allocated size of bitmaps field. */
205 int bitmaps_size; 205 ptrdiff_t bitmaps_size;
206 206
207 /* Last used bitmap index. */ 207 /* Last used bitmap index. */
208 int bitmaps_last; 208 ptrdiff_t bitmaps_last;
209 209
210 /* Which modifier keys are on which modifier bits? 210 /* Which modifier keys are on which modifier bits?
211 211
@@ -490,7 +490,7 @@ struct x_output
490 490
491 /* If >=0, a bitmap index. The indicated bitmap is used for the 491 /* If >=0, a bitmap index. The indicated bitmap is used for the
492 icon. */ 492 icon. */
493 int icon_bitmap; 493 ptrdiff_t icon_bitmap;
494 494
495 /* Default ASCII font of this frame. */ 495 /* Default ASCII font of this frame. */
496 struct font *font; 496 struct font *font;