From 78eb494ecaa1a20112080faedfd30e616c5be76b Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 10 May 2011 22:29:31 -0700 Subject: [PATCH 01/19] * window.c (size_window): Avoid needless test at loop start. --- src/ChangeLog | 4 ++++ src/window.c | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index f7010859baa..8dc51c0d01b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2011-05-11 Paul Eggert + + * window.c (size_window): Avoid needless test at loop start. + 2011-05-10 Juanma Barranquero * image.c (Finit_image_library): Return t for built-in image types, diff --git a/src/window.c b/src/window.c index 4dbee41c5f4..bc9f31e03e8 100644 --- a/src/window.c +++ b/src/window.c @@ -3094,11 +3094,14 @@ size_window (Lisp_Object window, int size, int width_p, int nodelete_p, int firs Lisp_Object last_child; int child_size; - for (child = *forward; !NILP (child); child = c->next) + child = *forward; + do { c = XWINDOW (child); last_child = child; + child = c->next; } + while (!NILP (child)); child_size = WINDOW_TOTAL_SIZE (c, width_p); size_window (last_child, size - old_size + child_size, From bc827e23be4630f4b5d7a1895e37cfab89eb6b6a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 11 May 2011 14:42:11 -0700 Subject: [PATCH 02/19] * lisp.h (XINT) [USE_LISP_UNION_TYPE]: Cast to EMACS_INT. (XUINT) [USE_LISP_UNION_TYPE]: Cast to EMACS_UINT. Otherwise, GCC 4.6.0 warns about printf (pI, XINT (...)), presumably because the widths might not match. --- src/ChangeLog | 5 +++++ src/lisp.h | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8dc51c0d01b..550dd28eb24 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2011-05-11 Paul Eggert + * lisp.h (XINT) [USE_LISP_UNION_TYPE]: Cast to EMACS_INT. + (XUINT) [USE_LISP_UNION_TYPE]: Cast to EMACS_UINT. + Otherwise, GCC 4.6.0 warns about printf (pI, XINT (...)), + presumably because the widths might not match. + * window.c (size_window): Avoid needless test at loop start. 2011-05-10 Juanma Barranquero diff --git a/src/lisp.h b/src/lisp.h index 66f5c962be8..2342ea2bdbe 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -470,8 +470,8 @@ enum pvec_type #define XHASH(a) ((a).i) #define XTYPE(a) ((enum Lisp_Type) (a).u.type) -#define XINT(a) ((a).s.val) -#define XUINT(a) ((a).u.val) +#define XINT(a) ((EMACS_INT) (a).s.val) +#define XUINT(a) ((EMACS_UINT) (a).u.val) #ifdef USE_LSB_TAG From 5235bd3eb16b94dc5dcef3b1447f821fc09ea930 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 11 May 2011 16:16:52 -0700 Subject: [PATCH 03/19] * xterm.c: Use EMACS_INT for Emacs modifiers, and int for X modifiers. Before, the code was not consistent. These values cannot exceed 2**31 - 1 so there's no need to make them unsigned. (x_x_to_emacs_modifiers): Accept int and return EMACS_INT. (x_emacs_to_x_modifiers): Accept EMACS_INT and return int. (x_x_to_emacs_modifiers, x_emacs_to_x_modifiers): Reject non-integers as modifiers. * xterm.h (x_x_to_emacs_modifiers): Adjust to signature change. --- src/ChangeLog | 9 +++++++++ src/xterm.c | 40 ++++++++++++++++++++-------------------- src/xterm.h | 3 +-- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 550dd28eb24..da468d47db3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,14 @@ 2011-05-11 Paul Eggert + * xterm.c: Use EMACS_INT for Emacs modifiers, and int for X modifiers. + Before, the code was not consistent. These values cannot exceed + 2**31 - 1 so there's no need to make them unsigned. + (x_x_to_emacs_modifiers): Accept int and return EMACS_INT. + (x_emacs_to_x_modifiers): Accept EMACS_INT and return int. + (x_x_to_emacs_modifiers, x_emacs_to_x_modifiers): Reject non-integers + as modifiers. + * xterm.h (x_x_to_emacs_modifiers): Adjust to signature change. + * lisp.h (XINT) [USE_LISP_UNION_TYPE]: Cast to EMACS_INT. (XUINT) [USE_LISP_UNION_TYPE]: Cast to EMACS_UINT. Otherwise, GCC 4.6.0 warns about printf (pI, XINT (...)), diff --git a/src/xterm.c b/src/xterm.c index 20259b7ab2e..f5886ab9628 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -3609,23 +3609,23 @@ x_find_modifier_meanings (struct x_display_info *dpyinfo) /* Convert between the modifier bits X uses and the modifier bits Emacs uses. */ -unsigned int -x_x_to_emacs_modifiers (struct x_display_info *dpyinfo, unsigned int state) +EMACS_INT +x_x_to_emacs_modifiers (struct x_display_info *dpyinfo, int state) { - EMACS_UINT mod_meta = meta_modifier; - EMACS_UINT mod_alt = alt_modifier; - EMACS_UINT mod_hyper = hyper_modifier; - EMACS_UINT mod_super = super_modifier; + EMACS_INT mod_meta = meta_modifier; + EMACS_INT mod_alt = alt_modifier; + EMACS_INT mod_hyper = hyper_modifier; + EMACS_INT mod_super = super_modifier; Lisp_Object tem; tem = Fget (Vx_alt_keysym, Qmodifier_value); - if (! EQ (tem, Qnil)) mod_alt = XUINT (tem); + if (INTEGERP (tem)) mod_alt = XINT (tem); tem = Fget (Vx_meta_keysym, Qmodifier_value); - if (! EQ (tem, Qnil)) mod_meta = XUINT (tem); + if (INTEGERP (tem)) mod_meta = XINT (tem); tem = Fget (Vx_hyper_keysym, Qmodifier_value); - if (! EQ (tem, Qnil)) mod_hyper = XUINT (tem); + if (INTEGERP (tem)) mod_hyper = XINT (tem); tem = Fget (Vx_super_keysym, Qmodifier_value); - if (! EQ (tem, Qnil)) mod_super = XUINT (tem); + if (INTEGERP (tem)) mod_super = XINT (tem); return ( ((state & (ShiftMask | dpyinfo->shift_lock_mask)) ? shift_modifier : 0) @@ -3636,24 +3636,24 @@ x_x_to_emacs_modifiers (struct x_display_info *dpyinfo, unsigned int state) | ((state & dpyinfo->hyper_mod_mask) ? mod_hyper : 0)); } -static unsigned int -x_emacs_to_x_modifiers (struct x_display_info *dpyinfo, unsigned int state) +static int +x_emacs_to_x_modifiers (struct x_display_info *dpyinfo, EMACS_INT state) { - EMACS_UINT mod_meta = meta_modifier; - EMACS_UINT mod_alt = alt_modifier; - EMACS_UINT mod_hyper = hyper_modifier; - EMACS_UINT mod_super = super_modifier; + int mod_meta = meta_modifier; + int mod_alt = alt_modifier; + int mod_hyper = hyper_modifier; + int mod_super = super_modifier; Lisp_Object tem; tem = Fget (Vx_alt_keysym, Qmodifier_value); - if (! EQ (tem, Qnil)) mod_alt = XUINT (tem); + if (INTEGERP (tem)) mod_alt = XINT (tem); tem = Fget (Vx_meta_keysym, Qmodifier_value); - if (! EQ (tem, Qnil)) mod_meta = XUINT (tem); + if (INTEGERP (tem)) mod_meta = XINT (tem); tem = Fget (Vx_hyper_keysym, Qmodifier_value); - if (! EQ (tem, Qnil)) mod_hyper = XUINT (tem); + if (INTEGERP (tem)) mod_hyper = XINT (tem); tem = Fget (Vx_super_keysym, Qmodifier_value); - if (! EQ (tem, Qnil)) mod_super = XUINT (tem); + if (INTEGERP (tem)) mod_super = XINT (tem); return ( ((state & mod_alt) ? dpyinfo->alt_mod_mask : 0) diff --git a/src/xterm.h b/src/xterm.h index fbd638fe73b..1b90b6d8ff4 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -989,8 +989,7 @@ extern void x_mouse_leave (struct x_display_info *); #ifdef USE_X_TOOLKIT extern int x_dispatch_event (XEvent *, Display *); #endif -extern unsigned int x_x_to_emacs_modifiers (struct x_display_info *, - unsigned); +extern EMACS_INT x_x_to_emacs_modifiers (struct x_display_info *, int); extern int x_display_pixel_height (struct x_display_info *); extern int x_display_pixel_width (struct x_display_info *); From d89eb65e6d3a46ef9d04a950ee24352c146e4ea0 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 11 May 2011 23:46:26 -0700 Subject: [PATCH 04/19] * xmenu.c (set_frame_menubar): Don't mishandle vectors with no nils. --- src/ChangeLog | 4 ++++ src/xmenu.c | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index da468d47db3..10b3ef2d6f2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2011-05-12 Paul Eggert + + * xmenu.c (set_frame_menubar): Don't mishandle vectors with no nils. + 2011-05-11 Paul Eggert * xterm.c: Use EMACS_INT for Emacs modifiers, and int for X modifiers. diff --git a/src/xmenu.c b/src/xmenu.c index 2a4359fa84a..898aade06c2 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -922,7 +922,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) #endif Lisp_Object items; widget_value *wv, *first_wv, *prev_wv = 0; - EMACS_UINT i, last_i = 0; + EMACS_UINT i, last_i; int *submenu_start, *submenu_end; int *submenu_top_level_items, *submenu_n_panes; @@ -1021,8 +1021,6 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) { Lisp_Object key, string, maps; - last_i = i; - key = XVECTOR (items)->contents[4 * i]; string = XVECTOR (items)->contents[4 * i + 1]; maps = XVECTOR (items)->contents[4 * i + 2]; @@ -1039,6 +1037,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) submenu_end[i] = menu_items_used; } + last_i = i; finish_menu_items (); /* Convert menu_items into widget_value trees From 5cc152c0804748eb4c872ff34fe5414669e10745 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 11 May 2011 23:48:32 -0700 Subject: [PATCH 05/19] * menu.c (grow_menu_items): Check for int overflow. --- src/ChangeLog | 2 ++ src/menu.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/ChangeLog b/src/ChangeLog index 10b3ef2d6f2..913dcc05a10 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2011-05-12 Paul Eggert + * menu.c (grow_menu_items): Check for int overflow. + * xmenu.c (set_frame_menubar): Don't mishandle vectors with no nils. 2011-05-11 Paul Eggert diff --git a/src/menu.c b/src/menu.c index 7a3edcb6f4f..705100381d5 100644 --- a/src/menu.c +++ b/src/menu.c @@ -176,6 +176,8 @@ save_menu_items (void) static void grow_menu_items (void) { + if ((INT_MAX - MENU_ITEMS_PANE_LENGTH) / 2 < menu_items_allocated) + memory_full (); menu_items_allocated *= 2; menu_items = larger_vector (menu_items, menu_items_allocated, Qnil); } From 3e26f69c4f5f7fe38081f0889186d6a9260c85e0 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 12 May 2011 09:16:40 -0700 Subject: [PATCH 06/19] * xmenu.c (set_frame_menubar): Use int, not EMACS_UINT, for indexes that always fit in int. Use a sentinel instead of a counter, to avoid a temp and to allay GCC's concerns about possible int overflow. --- src/ChangeLog | 4 ++++ src/xmenu.c | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 913dcc05a10..3bdf5129da9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2011-05-12 Paul Eggert + * xmenu.c (set_frame_menubar): Use int, not EMACS_UINT, for indexes + that always fit in int. Use a sentinel instead of a counter, to + avoid a temp and to allay GCC's concerns about possible int overflow. + * menu.c (grow_menu_items): Check for int overflow. * xmenu.c (set_frame_menubar): Don't mishandle vectors with no nils. diff --git a/src/xmenu.c b/src/xmenu.c index 898aade06c2..ccb60d2dcbb 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -922,7 +922,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) #endif Lisp_Object items; widget_value *wv, *first_wv, *prev_wv = 0; - EMACS_UINT i, last_i; + int i; int *submenu_start, *submenu_end; int *submenu_top_level_items, *submenu_n_panes; @@ -966,7 +966,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) Lisp_Object *previous_items = (Lisp_Object *) alloca (previous_menu_items_used * sizeof (Lisp_Object)); - EMACS_UINT subitems; + int subitems; /* If we are making a new widget, its contents are empty, do always reinitialize them. */ @@ -1012,7 +1012,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) menu_items = f->menu_bar_vector; menu_items_allocated = VECTORP (menu_items) ? ASIZE (menu_items) : 0; subitems = ASIZE (items) / 4; - submenu_start = (int *) alloca (subitems * sizeof (int)); + submenu_start = (int *) alloca ((subitems + 1) * sizeof (int)); submenu_end = (int *) alloca (subitems * sizeof (int)); submenu_n_panes = (int *) alloca (subitems * sizeof (int)); submenu_top_level_items = (int *) alloca (subitems * sizeof (int)); @@ -1037,7 +1037,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) submenu_end[i] = menu_items_used; } - last_i = i; + submenu_start[i] = -1; finish_menu_items (); /* Convert menu_items into widget_value trees @@ -1051,7 +1051,7 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p) wv->help = Qnil; first_wv = wv; - for (i = 0; i < last_i; i++) + for (i = 0; 0 <= submenu_start[i]; i++) { menu_items_n_panes = submenu_n_panes[i]; wv = digest_single_submenu (submenu_start[i], submenu_end[i], From d230cb74b5a1f6bb8d340e11ca1a661e5ce6a7ae Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 12 May 2011 09:25:30 -0700 Subject: [PATCH 07/19] * frame.h (struct frame): Use int for menu_bar_items_used instead of EMACS_INT, since it always fits in int. --- src/ChangeLog | 2 ++ src/frame.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 3bdf5129da9..42c91399095 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -3,6 +3,8 @@ * xmenu.c (set_frame_menubar): Use int, not EMACS_UINT, for indexes that always fit in int. Use a sentinel instead of a counter, to avoid a temp and to allay GCC's concerns about possible int overflow. + * frame.h (struct frame): Use int for menu_bar_items_used + instead of EMACS_INT, since it always fits in int. * menu.c (grow_menu_items): Check for int overflow. diff --git a/src/frame.h b/src/frame.h index e73370340f1..db57b1be980 100644 --- a/src/frame.h +++ b/src/frame.h @@ -192,7 +192,7 @@ struct frame struct face_cache *face_cache; /* Number of elements in `menu_bar_vector' that have meaningful data. */ - EMACS_INT menu_bar_items_used; + int menu_bar_items_used; /* A buffer to hold the frame's name. We can't use the Lisp string's pointer (`name', above) because it might get relocated. */ From 841f1b75c4724d853b94ba6fd6e3b87571d3dca6 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 12 May 2011 09:38:09 -0700 Subject: [PATCH 08/19] * xselect.c (last_event_timestamp): Remove duplicate decl. --- src/ChangeLog | 2 ++ src/xselect.c | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 42c91399095..8dd4ba209c1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2011-05-12 Paul Eggert + * xselect.c (last_event_timestamp): Remove duplicate decl. + * xmenu.c (set_frame_menubar): Use int, not EMACS_UINT, for indexes that always fit in int. Use a sentinel instead of a counter, to avoid a temp and to allay GCC's concerns about possible int overflow. diff --git a/src/xselect.c b/src/xselect.c index f11fc40fce8..e279b398149 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -121,10 +121,6 @@ static Lisp_Object Qforeign_selection; #define SELECTION_QUANTUM(dpy) ((XMaxRequestSize(dpy) << 2) - 100) -/* The timestamp of the last input event Emacs received from the X server. */ -/* Defined in keyboard.c. */ -extern unsigned long last_event_timestamp; - /* This is an association list whose elements are of the form ( SELECTION-NAME SELECTION-VALUE SELECTION-TIMESTAMP FRAME) SELECTION-NAME is a lisp symbol, whose name is the name of an X Atom. From 6434756cc552458f871b66dbd28692c8de69633c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 12 May 2011 10:18:58 -0700 Subject: [PATCH 09/19] * xselect.c (x_own_selection): Remove needless cast to unsigned long. --- src/ChangeLog | 1 + src/xselect.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8dd4ba209c1..4d6251f6bde 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,6 +1,7 @@ 2011-05-12 Paul Eggert * xselect.c (last_event_timestamp): Remove duplicate decl. + (x_own_selection): Remove needless cast to unsigned long. * xmenu.c (set_frame_menubar): Use int, not EMACS_UINT, for indexes that always fit in int. Use a sentinel instead of a counter, to diff --git a/src/xselect.c b/src/xselect.c index e279b398149..3ddd4c54b49 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -352,7 +352,7 @@ x_own_selection (Lisp_Object selection_name, Lisp_Object selection_value) Lisp_Object selection_data; Lisp_Object prev_value; - selection_time = long_to_cons ((unsigned long) timestamp); + selection_time = long_to_cons (timestamp); selection_data = list4 (selection_name, selection_value, selection_time, selected_frame); prev_value = assq_no_quit (selection_name, Vselection_alist); From 8e55734abd164a7b170380ce0413d1d792429ce8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 12 May 2011 12:37:40 -0700 Subject: [PATCH 10/19] * keyboard.c (make_lispy_event): Fix problem in integer overflow. Don't assume that the difference between two unsigned long values can fit into an integer. At this point, we know button_down_time <= event->timestamp, so the difference must be nonnegative, so there's no need to cast the result if double-click-time is nonnegative, as it should be; check that it's nonnegative, just in case. This bug is triggered when events are more than 2**31 ms apart (about 25 days). --- src/ChangeLog | 9 +++++++++ src/keyboard.c | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 4d6251f6bde..5760bfc2a1c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,14 @@ 2011-05-12 Paul Eggert + * keyboard.c (make_lispy_event): Fix problem in integer overflow. + Don't assume that the difference between two unsigned long values + can fit into an integer. At this point, we know button_down_time + <= event->timestamp, so the difference must be nonnegative, so + there's no need to cast the result if double-click-time is + nonnegative, as it should be; check that it's nonnegative, just in + case. This bug is triggered when events are more than 2**31 ms + apart (about 25 days). + * xselect.c (last_event_timestamp): Remove duplicate decl. (x_own_selection): Remove needless cast to unsigned long. diff --git a/src/keyboard.c b/src/keyboard.c index a94456fce2e..287996ffba9 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -5556,9 +5556,9 @@ make_lispy_event (struct input_event *event) && (eabs (XINT (event->y) - last_mouse_y) <= fuzz) && button_down_time != 0 && (EQ (Vdouble_click_time, Qt) - || (INTEGERP (Vdouble_click_time) - && ((int)(event->timestamp - button_down_time) - < XINT (Vdouble_click_time))))); + || (NATNUMP (Vdouble_click_time) + && (event->timestamp - button_down_time + < XFASTINT (Vdouble_click_time))))); } last_mouse_button = button; @@ -5742,9 +5742,9 @@ make_lispy_event (struct input_event *event) && (eabs (XINT (event->y) - last_mouse_y) <= fuzz) && button_down_time != 0 && (EQ (Vdouble_click_time, Qt) - || (INTEGERP (Vdouble_click_time) - && ((int)(event->timestamp - button_down_time) - < XINT (Vdouble_click_time))))); + || (NATNUMP (Vdouble_click_time) + && (event->timestamp - button_down_time + < XFASTINT (Vdouble_click_time))))); if (is_double) { double_click_count++; From 86db42d22397effbb6e9edc5ae11d806847f0d3e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 12 May 2011 13:00:02 -0700 Subject: [PATCH 11/19] Add Bug#. --- src/ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 5760bfc2a1c..b2b19b6c940 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -7,7 +7,7 @@ there's no need to cast the result if double-click-time is nonnegative, as it should be; check that it's nonnegative, just in case. This bug is triggered when events are more than 2**31 ms - apart (about 25 days). + apart (about 25 days). (Bug#8664) * xselect.c (last_event_timestamp): Remove duplicate decl. (x_own_selection): Remove needless cast to unsigned long. From 08dc5ae68e9c699410256ca9052bd09f336ac87f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 12 May 2011 13:23:33 -0700 Subject: [PATCH 12/19] Be more systematic about user-interface timestamps. Before, the code sometimes used 'Time', sometimes 'unsigned long', and sometimes 'EMACS_UINT', to represent these timestamps. This change causes it to use 'Time' uniformly, as that's what X uses. This makes the code easier to follow, and makes it easier to catch integer overflow bugs such as Bug#8664. * frame.c (Fmouse_position, Fmouse_pixel_position): Use Time, not unsigned long, for user-interface timestamps. * keyboard.c (last_event_timestamp, kbd_buffer_get_event): Likewise. (button_down_time, make_lispy_position, make_lispy_movement): Likewise. * keyboard.h (last_event_timestamp): Likewise. * menu.c (Fx_popup_menu) [!HAVE_X_WINDOWS]: Likewise. * menu.h (xmenu_show): Likewise. * term.c (term_mouse_position): Likewise. * termhooks.h (struct input_event.timestamp): Likewise. (struct terminal.mouse_position_hook): Likewise. * xmenu.c (create_and_show_popup_menu, xmenu_show): Likewise. * xterm.c (XTmouse_position, x_scroll_bar_report_motion): Likewise. * systime.h (Time): New decl. Pull it in from if HAVE_X_WINDOWS, otherwise define it as unsigned long, which is what it was before. * menu.h, termhooks.h: Include "systime.h", for Time. --- src/ChangeLog | 23 +++++++++++++++++++++++ src/frame.c | 4 ++-- src/keyboard.c | 10 +++++----- src/keyboard.h | 4 ++-- src/menu.c | 4 ++-- src/menu.h | 5 +++-- src/systime.h | 6 ++++++ src/term.c | 2 +- src/termhooks.h | 6 ++++-- src/xmenu.c | 13 +++++++------ src/xterm.c | 6 +++--- 11 files changed, 58 insertions(+), 25 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b2b19b6c940..a772106c521 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,28 @@ 2011-05-12 Paul Eggert + Be more systematic about user-interface timestamps. + Before, the code sometimes used 'Time', sometimes 'unsigned long', + and sometimes 'EMACS_UINT', to represent these timestamps. This + change causes it to use 'Time' uniformly, as that's what X uses. + This makes the code easier to follow, and makes it easier to catch + integer overflow bugs such as Bug#8664. + * frame.c (Fmouse_position, Fmouse_pixel_position): + Use Time, not unsigned long, for user-interface timestamps. + * keyboard.c (last_event_timestamp, kbd_buffer_get_event): Likewise. + (button_down_time, make_lispy_position, make_lispy_movement): Likewise. + * keyboard.h (last_event_timestamp): Likewise. + * menu.c (Fx_popup_menu) [!HAVE_X_WINDOWS]: Likewise. + * menu.h (xmenu_show): Likewise. + * term.c (term_mouse_position): Likewise. + * termhooks.h (struct input_event.timestamp): Likewise. + (struct terminal.mouse_position_hook): Likewise. + * xmenu.c (create_and_show_popup_menu, xmenu_show): Likewise. + * xterm.c (XTmouse_position, x_scroll_bar_report_motion): Likewise. + * systime.h (Time): New decl. Pull it in from if + HAVE_X_WINDOWS, otherwise define it as unsigned long, which is + what it was before. + * menu.h, termhooks.h: Include "systime.h", for Time. + * keyboard.c (make_lispy_event): Fix problem in integer overflow. Don't assume that the difference between two unsigned long values can fit into an integer. At this point, we know button_down_time diff --git a/src/frame.c b/src/frame.c index b106c568e48..ce92a83b86c 100644 --- a/src/frame.c +++ b/src/frame.c @@ -1631,7 +1631,7 @@ and returns whatever that function returns. */) enum scroll_bar_part party_dummy; Lisp_Object x, y, retval; int col, row; - unsigned long long_dummy; + Time long_dummy; struct gcpro gcpro1; f = SELECTED_FRAME (); @@ -1676,7 +1676,7 @@ and nil for X and Y. */) Lisp_Object lispy_dummy; enum scroll_bar_part party_dummy; Lisp_Object x, y; - unsigned long long_dummy; + Time long_dummy; f = SELECTED_FRAME (); x = y = Qnil; diff --git a/src/keyboard.c b/src/keyboard.c index 287996ffba9..c471a91ebfb 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -238,7 +238,7 @@ Lisp_Object internal_last_event_frame; /* The timestamp of the last input event we received from the X server. X Windows wants this for selection ownership. */ -unsigned long last_event_timestamp; +Time last_event_timestamp; static Lisp_Object Qx_set_selection, Qhandle_switch_frame; Lisp_Object QPRIMARY; @@ -4085,7 +4085,7 @@ kbd_buffer_get_event (KBOARD **kbp, Lisp_Object bar_window; enum scroll_bar_part part; Lisp_Object x, y; - unsigned long t; + Time t; *kbp = current_kboard; /* Note that this uses F to determine which terminal to look at. @@ -5088,7 +5088,7 @@ static Lisp_Object button_down_location; static int last_mouse_button; static int last_mouse_x; static int last_mouse_y; -static unsigned long button_down_time; +static Time button_down_time; /* The number of clicks in this multiple-click. */ @@ -5099,7 +5099,7 @@ static int double_click_count; static Lisp_Object make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y, - unsigned long t) + Time t) { enum window_part part; Lisp_Object posn = Qnil; @@ -5987,7 +5987,7 @@ make_lispy_event (struct input_event *event) static Lisp_Object make_lispy_movement (FRAME_PTR frame, Lisp_Object bar_window, enum scroll_bar_part part, - Lisp_Object x, Lisp_Object y, unsigned long t) + Lisp_Object x, Lisp_Object y, Time t) { /* Is it a scroll bar movement? */ if (frame && ! NILP (bar_window)) diff --git a/src/keyboard.h b/src/keyboard.h index 1f5cbd23639..802c99edb5e 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ -#include "systime.h" /* for EMACS_TIME */ +#include "systime.h" /* for EMACS_TIME, Time */ #include "coding.h" /* for ENCODE_UTF_8 and ENCODE_SYSTEM */ /* Lisp fields in struct keyboard are hidden from most code and accessed @@ -459,7 +459,7 @@ extern Lisp_Object Qevent_symbol_element_mask; /* The timestamp of the last input event we received from the X server. X Windows wants this for selection ownership. */ -extern unsigned long last_event_timestamp; +extern Time last_event_timestamp; extern int quit_char; diff --git a/src/menu.c b/src/menu.c index 705100381d5..d2486439fd0 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1147,13 +1147,13 @@ no quit occurs and `x-popup-menu' returns nil. */) #else /* not HAVE_X_WINDOWS */ Lisp_Object bar_window; enum scroll_bar_part part; - unsigned long time; + Time time; void (*mouse_position_hook) (struct frame **, int, Lisp_Object *, enum scroll_bar_part *, Lisp_Object *, Lisp_Object *, - unsigned long *) = + Time *) = FRAME_TERMINAL (new_f)->mouse_position_hook; if (mouse_position_hook) diff --git a/src/menu.h b/src/menu.h index c3978dae8eb..451401b42d5 100644 --- a/src/menu.h +++ b/src/menu.h @@ -19,6 +19,8 @@ along with GNU Emacs. If not, see . */ #ifndef MENU_H #define MENU_H +#include "systime.h" /* for Time */ + extern void x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval); @@ -48,6 +50,5 @@ extern Lisp_Object w32_menu_show (FRAME_PTR, int, int, int, int, extern Lisp_Object ns_menu_show (FRAME_PTR, int, int, int, int, Lisp_Object, const char **); extern Lisp_Object xmenu_show (FRAME_PTR, int, int, int, int, - Lisp_Object, const char **, EMACS_UINT); + Lisp_Object, const char **, Time); #endif /* MENU_H */ - diff --git a/src/systime.h b/src/systime.h index cb1ea230f7d..db43b26dc5e 100644 --- a/src/systime.h +++ b/src/systime.h @@ -30,6 +30,12 @@ along with GNU Emacs. If not, see . */ #endif #endif +#ifdef HAVE_X_WINDOWS +# include +#else +typedef unsigned long Time; +#endif + #ifdef HAVE_TZNAME #ifndef tzname /* For SGI. */ extern char *tzname[]; /* RS6000 and others want it this way. */ diff --git a/src/term.c b/src/term.c index c68228cc51a..34320a1ad6d 100644 --- a/src/term.c +++ b/src/term.c @@ -2698,7 +2698,7 @@ term_mouse_movement (FRAME_PTR frame, Gpm_Event *event) static void term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, enum scroll_bar_part *part, Lisp_Object *x, - Lisp_Object *y, unsigned long *timeptr) + Lisp_Object *y, Time *timeptr) { struct timeval now; diff --git a/src/termhooks.h b/src/termhooks.h index 3a49b49aede..34e1364effd 100644 --- a/src/termhooks.h +++ b/src/termhooks.h @@ -20,6 +20,8 @@ along with GNU Emacs. If not, see . */ /* Miscellanea. */ +#include "systime.h" /* for Time */ + struct glyph; struct frame; @@ -233,7 +235,7 @@ struct input_event int modifiers; /* See enum below for interpretation. */ Lisp_Object x, y; - unsigned long timestamp; + Time timestamp; /* This is padding just to put the frame_or_window field past the size of struct selection_input_event. */ @@ -463,7 +465,7 @@ struct terminal enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y, - unsigned long *); + Time *); /* The window system handling code should set this if the mouse has moved since the last call to the mouse_position_hook. Calling that diff --git a/src/xmenu.c b/src/xmenu.c index ccb60d2dcbb..7d7515a8f25 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -240,7 +240,7 @@ for instance using the window manager, then this produces a quit and FRAME_PTR new_f = SELECTED_FRAME (); Lisp_Object bar_window; enum scroll_bar_part part; - unsigned long time; + Time time; Lisp_Object x, y; (*mouse_position_hook) (&new_f, 1, &bar_window, &part, &x, &y, &time); @@ -1420,7 +1420,8 @@ pop_down_menu (Lisp_Object arg) menu pops down. menu_item_selection will be set to the selection. */ static void -create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y, int for_click, EMACS_UINT timestamp) +create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y, + int for_click, Time timestamp) { int i; GtkWidget *menu; @@ -1464,7 +1465,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y, i gtk_widget_show_all (menu); gtk_menu_popup (GTK_MENU (menu), 0, 0, pos_func, &popup_x_y, i, - timestamp > 0 ? timestamp : gtk_get_current_event_time()); + timestamp ? timestamp : gtk_get_current_event_time ()); record_unwind_protect (pop_down_menu, make_save_value (menu, 0)); @@ -1524,7 +1525,7 @@ pop_down_menu (Lisp_Object arg) menu_item_selection will be set to the selection. */ static void create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, - int x, int y, int for_click, EMACS_UINT timestamp) + int x, int y, int for_click, Time timestamp) { int i; Arg av[2]; @@ -1598,7 +1599,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, Lisp_Object xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, - Lisp_Object title, const char **error_name, EMACS_UINT timestamp) + Lisp_Object title, const char **error_name, Time timestamp) { int i; widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0; @@ -2241,7 +2242,7 @@ pop_down_menu (Lisp_Object arg) Lisp_Object xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, - Lisp_Object title, const char **error_name, EMACS_UINT timestamp) + Lisp_Object title, const char **error_name, Time timestamp) { Window root; XMenu *menu; diff --git a/src/xterm.c b/src/xterm.c index f5886ab9628..71dc6f16858 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -342,7 +342,7 @@ static struct scroll_bar *x_window_to_scroll_bar (Display *, Window); static void x_scroll_bar_report_motion (struct frame **, Lisp_Object *, enum scroll_bar_part *, Lisp_Object *, Lisp_Object *, - unsigned long *); + Time *); static void x_handle_net_wm_state (struct frame *, XPropertyEvent *); static void x_check_fullscreen (struct frame *); static void x_check_expected_move (struct frame *, int, int); @@ -3799,7 +3799,7 @@ redo_mouse_highlight (void) static void XTmouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y, - long unsigned int *timestamp) + Time *timestamp) { FRAME_PTR f1; @@ -5534,7 +5534,7 @@ x_scroll_bar_note_movement (struct scroll_bar *bar, XEvent *event) static void x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window, enum scroll_bar_part *part, Lisp_Object *x, - Lisp_Object *y, long unsigned int *timestamp) + Lisp_Object *y, Time *timestamp) { struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); Window w = bar->x_window; From f6a24d19906993b975e7be822abbb3cfce719751 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 12 May 2011 13:30:05 -0700 Subject: [PATCH 13/19] * term.c (term_mouse_position): Don't assume time_t wraparound. --- src/ChangeLog | 3 +++ src/term.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index a772106c521..21c03ba8220 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ 2011-05-12 Paul Eggert + * term.c (term_mouse_position): Don't assume time_t wraparound. + Be more systematic about user-interface timestamps. Before, the code sometimes used 'Time', sometimes 'unsigned long', and sometimes 'EMACS_UINT', to represent these timestamps. This @@ -14,6 +16,7 @@ * menu.c (Fx_popup_menu) [!HAVE_X_WINDOWS]: Likewise. * menu.h (xmenu_show): Likewise. * term.c (term_mouse_position): Likewise. + * termhooks.h (struct input_event.timestamp): Likewise. (struct terminal.mouse_position_hook): Likewise. * xmenu.c (create_and_show_popup_menu, xmenu_show): Likewise. diff --git a/src/term.c b/src/term.c index 34320a1ad6d..5fe258caa29 100644 --- a/src/term.c +++ b/src/term.c @@ -2701,6 +2701,7 @@ term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, Lisp_Object *y, Time *timeptr) { struct timeval now; + Time sec, usec; *fp = SELECTED_FRAME (); (*fp)->mouse_moved = 0; @@ -2711,7 +2712,9 @@ term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, XSETINT (*x, last_mouse_x); XSETINT (*y, last_mouse_y); gettimeofday(&now, 0); - *timeptr = (now.tv_sec * 1000) + (now.tv_usec / 1000); + sec = now.tv_sec; + usec = now.tv_usec; + *timeptr = (sec * 1000) + (usec / 1000); } /* Prepare a mouse-event in *RESULT for placement in the input queue. From d4e3e4d3ad71e45bcb15781e3f95ebb2687502a2 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 12 May 2011 18:10:46 -0700 Subject: [PATCH 14/19] * dispextern.h (struct image): Don't assume time_t <= unsigned long. * image.c (clear_image_cache): Likewise. --- src/ChangeLog | 5 +++++ src/dispextern.h | 2 +- src/image.c | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 21c03ba8220..d522c639a6f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2011-05-13 Paul Eggert + + * dispextern.h (struct image): Don't assume time_t <= unsigned long. + * image.c (clear_image_cache): Likewise. + 2011-05-12 Paul Eggert * term.c (term_mouse_position): Don't assume time_t wraparound. diff --git a/src/dispextern.h b/src/dispextern.h index 72e23e6642a..77c45cf2fc6 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -2709,7 +2709,7 @@ struct image { /* The time in seconds at which the image was last displayed. Set in prepare_image_for_display. */ - unsigned long timestamp; + time_t timestamp; /* Pixmaps of the image. */ Pixmap pixmap, mask; diff --git a/src/image.c b/src/image.c index 23da03b6264..2562d79a782 100644 --- a/src/image.c +++ b/src/image.c @@ -1523,7 +1523,7 @@ clear_image_cache (struct frame *f, Lisp_Object filter) { /* Free cache based on timestamp. */ EMACS_TIME t; - unsigned long old; + time_t old; int delay, nimages = 0; for (i = 0; i < c->used; ++i) From bcfc5c821c672e38e5d4fad78347ab3c3f4352f7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 12 May 2011 18:11:23 -0700 Subject: [PATCH 15/19] Omit newline. --- src/ChangeLog | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index d522c639a6f..378d8a22808 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -21,7 +21,6 @@ * menu.c (Fx_popup_menu) [!HAVE_X_WINDOWS]: Likewise. * menu.h (xmenu_show): Likewise. * term.c (term_mouse_position): Likewise. - * termhooks.h (struct input_event.timestamp): Likewise. (struct terminal.mouse_position_hook): Likewise. * xmenu.c (create_and_show_popup_menu, xmenu_show): Likewise. From 2d165e9dc58924db64f73791a638c136bc6324d7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 12 May 2011 23:12:24 -0700 Subject: [PATCH 16/19] * editfns.c (Fformat): Fix several integer overflow problems. For example, without this change, (format "%2147483648d" 1) dumps core on x86-64 GNU/Linux. Use EMACS_INT, not size_t, for sizes, since we prefer using signed values, and EMACS_INT will be big enough soon, even on 32-bit hosts. Also, prefer EMACS_INT to int for sizes. Don't assume that pI is either "l" or ""; it might be "ll" or "I64". Check for width and precision greater than INT_MAX, as this can make sprintf go kaflooey. (Bug#8668) --- src/ChangeLog | 9 ++++++++ src/editfns.c | 64 +++++++++++++++++++++++++++++---------------------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 378d8a22808..9bdbb9a7d18 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,14 @@ 2011-05-13 Paul Eggert + * editfns.c (Fformat): Fix several integer overflow problems. + For example, without this change, (format "%2147483648d" 1) dumps + core on x86-64 GNU/Linux. Use EMACS_INT, not size_t, for sizes, + since we prefer using signed values, and EMACS_INT will be big + enough soon, even on 32-bit hosts. Also, prefer EMACS_INT to int + for sizes. Don't assume that pI is either "l" or ""; it might be + "ll" or "I64". Check for width and precision greater than + INT_MAX, as this can make sprintf go kaflooey. (Bug#8668) + * dispextern.h (struct image): Don't assume time_t <= unsigned long. * image.c (clear_image_cache): Likewise. diff --git a/src/editfns.c b/src/editfns.c index 5e1dcce0275..b5ccb481c43 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3583,11 +3583,12 @@ specifier truncates the string to the given width. usage: (format STRING &rest OBJECTS) */) (size_t nargs, register Lisp_Object *args) { - register size_t n; /* The number of the next arg to substitute */ - register size_t total; /* An estimate of the final length */ + register EMACS_INT n; /* The number of the next arg to substitute */ + register EMACS_INT total; /* An estimate of the final length */ + int pIlen = sizeof pI - 1; char *buf, *p; register char *format, *end, *format_start; - int nchars; + EMACS_INT nchars; /* Nonzero if the output should be a multibyte string, which is true if any of the inputs is one. */ int multibyte = 0; @@ -3603,7 +3604,7 @@ usage: (format STRING &rest OBJECTS) */) no argument, *will* be assigned to in the case that a `%' and `.' occur after the final format specifier. */ int *precision = (int *) (alloca ((nargs + 1) * sizeof (int))); - int longest_format; + EMACS_INT longest_format; Lisp_Object val; int arg_intervals = 0; USE_SAFE_ALLOCA; @@ -3619,7 +3620,8 @@ usage: (format STRING &rest OBJECTS) */) info[0] is unused. Unused elements have -1 for start. */ struct info { - int start, end, intervals; + EMACS_INT start, end; + int intervals; } *info = 0; /* It should not be necessary to GCPRO ARGS, because @@ -3660,8 +3662,8 @@ usage: (format STRING &rest OBJECTS) */) /* Allocate the info and discarded tables. */ { - size_t nbytes = (nargs+1) * sizeof *info; - size_t i; + EMACS_INT nbytes = (nargs + 1) * sizeof *info; + EMACS_INT i; if (!info) info = (struct info *) alloca (nbytes); memset (info, 0, nbytes); @@ -3706,25 +3708,33 @@ usage: (format STRING &rest OBJECTS) */) || * format == ' ' || *format == '+')) ++format; + /* Parse width and precision, limiting them to the range of 'int' + because otherwise the underyling sprintf may go kaflooey. */ + if (*format >= '0' && *format <= '9') { - for (field_width = 0; *format >= '0' && *format <= '9'; ++format) - field_width = 10 * field_width + *format - '0'; + char *width_end; + unsigned long width = strtoul (format, &width_end, 10); + if (INT_MAX < width) + error ("Format string field width too large"); + field_width = width; + format = width_end; } /* N is not incremented for another few lines below, so refer to element N+1 (which might be precision[NARGS]). */ if (*format == '.') { - ++format; - for (precision[n+1] = 0; *format >= '0' && *format <= '9'; ++format) - precision[n+1] = 10 * precision[n+1] + *format - '0'; + char *prec_end; + unsigned long prec = strtoul (format + 1, &prec_end, 10); + if (INT_MAX < prec) + error ("Format string precision too large"); + precision[n + 1] = prec; + format = prec_end; } - /* Extra +1 for 'l' that we may need to insert into the - format. */ - if (format - this_format_start + 2 > longest_format) - longest_format = format - this_format_start + 2; + if (longest_format < format - this_format_start + pIlen + 1) + longest_format = format - this_format_start + pIlen + 1; if (format == end) error ("Format string ends in middle of format specifier"); @@ -3975,24 +3985,22 @@ usage: (format STRING &rest OBJECTS) */) } else if (INTEGERP (args[n]) || FLOATP (args[n])) { - int this_nchars; + EMACS_INT this_nchars; + EMACS_INT this_format_len = format - this_format_start; - memcpy (this_format, this_format_start, - format - this_format_start); - this_format[format - this_format_start] = 0; + memcpy (this_format, this_format_start, this_format_len); + this_format[this_format_len] = 0; if (format[-1] == 'e' || format[-1] == 'f' || format[-1] == 'g') sprintf (p, this_format, XFLOAT_DATA (args[n])); else { - if (sizeof (EMACS_INT) > sizeof (int) - && format[-1] != 'c') + if (pIlen && format[-1] != 'c') { - /* Insert 'l' before format spec. */ - this_format[format - this_format_start] - = this_format[format - this_format_start - 1]; - this_format[format - this_format_start - 1] = 'l'; - this_format[format - this_format_start + 1] = 0; + /* Insert pI before format spec. */ + memcpy (&this_format[this_format_len - 1], pI, pIlen); + this_format[this_format_len + pIlen - 1] = format[-1]; + this_format[this_format_len + pIlen] = 0; } if (INTEGERP (args[n])) @@ -4089,7 +4097,7 @@ usage: (format STRING &rest OBJECTS) */) if (CONSP (props)) { EMACS_INT bytepos = 0, position = 0, translated = 0; - int argn = 1; + EMACS_INT argn = 1; Lisp_Object list; /* Adjust the bounds of each text property From 66699ad31291ec329760966945ec4d4ad4688586 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 13 May 2011 11:08:56 -0700 Subject: [PATCH 17/19] * fns.c: Fix misspellings. --- src/fns.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fns.c b/src/fns.c index 47ded456c6e..16dc0fe0de2 100644 --- a/src/fns.c +++ b/src/fns.c @@ -457,10 +457,10 @@ concat (size_t nargs, Lisp_Object *args, Lisp_Object prev; int some_multibyte; /* When we make a multibyte string, we can't copy text properties - while concatinating each string because the length of resulting - string can't be decided until we finish the whole concatination. + while concatenating each string because the length of resulting + string can't be decided until we finish the whole concatenation. So, we record strings that have text properties to be copied - here, and copy the text properties after the concatination. */ + here, and copy the text properties after the concatenation. */ struct textprop_rec *textprops = NULL; /* Number of elements in textprops. */ int num_textprops = 0; @@ -704,7 +704,7 @@ concat (size_t nargs, Lisp_Object *args, make_number (0), make_number (SCHARS (this)), Qnil); - /* If successive arguments have properites, be sure that the + /* If successive arguments have properties, be sure that the value of `composition' property be the copy. */ if (last_to_end == textprops[argnum].to) make_composition_value_copy (props); @@ -2076,7 +2076,7 @@ internal_equal (register Lisp_Object o1, register Lisp_Object o2, int depth, int return compare_window_configurations (o1, o2, 0); /* Aside from them, only true vectors, char-tables, compiled - functions, and fonts (font-spec, font-entity, font-ojbect) + functions, and fonts (font-spec, font-entity, font-object) are sensible to compare, so eliminate the others now. */ if (size & PSEUDOVECTOR_FLAG) { @@ -2782,7 +2782,7 @@ ITEM should be one of the following: `months', returning a 12-element vector of month names (locale items MON_n); `paper', returning a list (WIDTH HEIGHT) for the default paper size, - both measured in milimeters (locale items PAPER_WIDTH, PAPER_HEIGHT). + both measured in millimeters (locale items PAPER_WIDTH, PAPER_HEIGHT). If the system can't provide such information through a call to `nl_langinfo', or if ITEM isn't from the list above, return nil. From 1a1f33668536488bb146bbd83cd0df741c4d9cdc Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 14 May 2011 02:03:53 -0700 Subject: [PATCH 18/19] Fixups, following up to the user-interface timestamp change. * nsterm.m (last_mouse_movement_time, ns_mouse_position): Use Time for UI timestamps, instead of unsigned long. * w32gui.h (Time): Define by including "systime.h" rather than by declaring it ourselves. (Bug#8664) --- src/ChangeLog | 8 ++++++++ src/nsterm.m | 6 ++---- src/w32gui.h | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 9bdbb9a7d18..dca9a174c34 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2011-05-14 Paul Eggert + + Fixups, following up to the user-interface timestamp change. + * nsterm.m (last_mouse_movement_time, ns_mouse_position): Use Time + for UI timestamps, instead of unsigned long. + * w32gui.h (Time): Define by including "systime.h" rather than by + declaring it ourselves. (Bug#8664) + 2011-05-13 Paul Eggert * editfns.c (Fformat): Fix several integer overflow problems. diff --git a/src/nsterm.m b/src/nsterm.m index c4756dc83cd..ac9c44a57a9 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -158,7 +158,7 @@ long context_menu_value = 0; /* display update */ NSPoint last_mouse_motion_position; static NSRect last_mouse_glyph; -static unsigned long last_mouse_movement_time = 0; +static Time last_mouse_movement_time = 0; static Lisp_Object last_mouse_motion_frame; static EmacsScroller *last_mouse_scroll_bar = nil; static struct frame *ns_updating_frame; @@ -1789,7 +1789,7 @@ note_mouse_movement (struct frame *frame, float x, float y) static void ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y, - unsigned long *time) + Time *time) /* -------------------------------------------------------------------------- External (hook): inform emacs about mouse position and hit parts. If a scrollbar is being dragged, set bar_window, part, x, y, time. @@ -6531,5 +6531,3 @@ baseline level. The default value is nil. */); /* Tell emacs about this window system. */ Fprovide (intern ("ns"), Qnil); } - - diff --git a/src/w32gui.h b/src/w32gui.h index 936709af181..2ba9cb53e22 100644 --- a/src/w32gui.h +++ b/src/w32gui.h @@ -20,6 +20,8 @@ along with GNU Emacs. If not, see . */ #define EMACS_W32GUI_H #include +#include "systime.h" /* for Time */ + /* Local memory management for menus. */ #define local_heap (GetProcessHeap ()) #define local_alloc(n) (HeapAlloc (local_heap, HEAP_ZERO_MEMORY, (n))) @@ -47,7 +49,6 @@ typedef char * XrmDatabase; typedef XGCValues * GC; typedef COLORREF Color; -typedef DWORD Time; typedef HWND Window; typedef HDC Display; /* HDC so it doesn't conflict with xpm lib. */ typedef HCURSOR Cursor; @@ -147,4 +148,3 @@ typedef struct { #endif /* EMACS_W32GUI_H */ - From 9fbd68410f1680b5b9bc2d56c239183ea13c7d58 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 14 May 2011 12:06:08 -0700 Subject: [PATCH 19/19] * msdos.c (mouse_get_pos): Likewise. * w32inevt.c (movement_time, w32_console_mouse_position): Likewise. --- src/ChangeLog | 2 ++ src/msdos.c | 2 +- src/w32inevt.c | 5 ++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index dca9a174c34..84575a82eb6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -3,6 +3,8 @@ Fixups, following up to the user-interface timestamp change. * nsterm.m (last_mouse_movement_time, ns_mouse_position): Use Time for UI timestamps, instead of unsigned long. + * msdos.c (mouse_get_pos): Likewise. + * w32inevt.c (movement_time, w32_console_mouse_position): Likewise. * w32gui.h (Time): Define by including "systime.h" rather than by declaring it ourselves. (Bug#8664) diff --git a/src/msdos.c b/src/msdos.c index 3dc586e42f5..73804df55cc 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -287,7 +287,7 @@ mouse_button_depressed (int b, int *xp, int *yp) void mouse_get_pos (FRAME_PTR *f, int insist, Lisp_Object *bar_window, enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y, - unsigned long *time) + Time *time) { int ix, iy; Lisp_Object frame, tail; diff --git a/src/w32inevt.c b/src/w32inevt.c index 465f5ccb70f..fddde61663f 100644 --- a/src/w32inevt.c +++ b/src/w32inevt.c @@ -45,7 +45,7 @@ extern HANDLE keyboard_handle; /* Info for last mouse motion */ static COORD movement_pos; -static DWORD movement_time; +static Time movement_time; /* from w32fns.c */ extern unsigned int map_keypad_keys (unsigned int, unsigned int); @@ -544,7 +544,7 @@ w32_console_mouse_position (FRAME_PTR *f, enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y, - unsigned long *time) + Time *time) { BLOCK_INPUT; @@ -756,4 +756,3 @@ w32_console_read_socket (struct terminal *terminal, UNBLOCK_INPUT; return ret; } -