[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r104265: Int overflow fixes, e.g., st
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r104265: Int overflow fixes, e.g., string length overflow. |
Date: |
Tue, 17 May 2011 17:52:24 -0700 |
User-agent: |
Bazaar (2.3.1) |
------------------------------------------------------------
revno: 104265 [merge]
fixes bug(s): http://debbugs.gnu.org/8675 http://debbugs.gnu.org/8664
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Tue 2011-05-17 17:52:24 -0700
message:
Int overflow fixes, e.g., string length overflow.
modified:
src/ChangeLog
src/alloc.c
src/character.c
src/character.h
src/dispextern.h
src/fns.c
src/frame.c
src/frame.h
src/image.c
src/insdel.c
src/keyboard.c
src/keyboard.h
src/lisp.h
src/menu.c
src/menu.h
src/msdos.c
src/nsterm.m
src/systime.h
src/term.c
src/termhooks.h
src/w32gui.h
src/w32inevt.c
src/w32menu.c
src/window.c
src/xmenu.c
src/xselect.c
src/xterm.c
src/xterm.h
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2011-05-18 00:26:48 +0000
+++ b/src/ChangeLog 2011-05-18 00:47:42 +0000
@@ -1,3 +1,98 @@
+2011-05-18 Paul Eggert <address@hidden>
+
+ Fix some integer overflow issues, such as string length overflow.
+
+ * insdel.c (count_size_as_multibyte): Check for string overflow.
+
+ * character.c (lisp_string_width): Check for string overflow.
+ Use EMACS_INT, not int, for string indexes and lengths; in
+ particular, 2nd arg is now EMACS_INT, not int. Do not crash if
+ the resulting string length overflows an EMACS_INT; instead,
+ report a string overflow if no precision given. When checking for
+ precision exhaustion, use a check that cannot possibly have
+ integer overflow. (Bug#8675)
+ * character.h (lisp_string_width): Adjust to new signature.
+
+ * alloc.c (string_overflow): New function.
+ (Fmake_string): Use it. This doesn't change behavior, but saves
+ a few bytes and will simplify future changes.
+ * character.c (string_escape_byte8): Likewise.
+ * lisp.h (string_overflow): New decl.
+
+ 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)
+
+ * dispextern.h (struct image): Don't assume time_t <= unsigned long.
+ * image.c (clear_image_cache): Likewise.
+
+ * 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
+ 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 <X11/X.h> 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
+ <= 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). (Bug#8664)
+
+ * 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
+ 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.
+
+ * xmenu.c (set_frame_menubar): Don't mishandle vectors with no nils.
+
+ * 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 (...)),
+ presumably because the widths might not match.
+
+ * window.c (size_window): Avoid needless test at loop start.
+
2011-05-18 Courtney Bane <address@hidden> (tiny change)
* term.c (Fresume_tty): Restore hooks before reinitializing (bug#8687).
=== modified file 'src/alloc.c'
--- a/src/alloc.c 2011-05-12 07:07:06 +0000
+++ b/src/alloc.c 2011-05-16 01:11:54 +0000
@@ -2174,6 +2174,11 @@
current_sblock = tb;
}
+void
+string_overflow (void)
+{
+ error ("Maximum string size exceeded");
+}
DEFUN ("make-string", Fmake_string, Smake_string, 2, 2, 0,
doc: /* Return a newly created string of length LENGTH, with INIT in
each element.
@@ -2206,7 +2211,7 @@
EMACS_INT string_len = XINT (length);
if (string_len > MOST_POSITIVE_FIXNUM / len)
- error ("Maximum string size exceeded");
+ string_overflow ();
nbytes = len * string_len;
val = make_uninit_multibyte_string (string_len, nbytes);
p = SDATA (val);
=== modified file 'src/character.c'
--- a/src/character.c 2011-05-12 07:07:06 +0000
+++ b/src/character.c 2011-05-16 05:18:38 +0000
@@ -35,6 +35,7 @@
#include <sys/types.h>
#include <setjmp.h>
+#include <intprops.h>
#include "lisp.h"
#include "character.h"
#include "buffer.h"
@@ -404,7 +405,7 @@
in *NCHARS and *NBYTES respectively. */
EMACS_INT
-lisp_string_width (Lisp_Object string, int precision,
+lisp_string_width (Lisp_Object string, EMACS_INT precision,
EMACS_INT *nchars, EMACS_INT *nbytes)
{
EMACS_INT len = SCHARS (string);
@@ -419,7 +420,7 @@
while (i < len)
{
- int chars, bytes, thiswidth;
+ EMACS_INT chars, bytes, thiswidth;
Lisp_Object val;
int cmp_id;
EMACS_INT ignore, end;
@@ -437,7 +438,11 @@
int c;
if (multibyte)
- c = STRING_CHAR_AND_LENGTH (str + i_byte, bytes);
+ {
+ int cbytes;
+ c = STRING_CHAR_AND_LENGTH (str + i_byte, cbytes);
+ bytes = cbytes;
+ }
else
c = str[i_byte], bytes = 1;
chars = 1;
@@ -455,8 +460,14 @@
}
}
- if (precision > 0
- && (width + thiswidth > precision))
+ if (precision <= 0)
+ {
+#ifdef emacs
+ if (INT_ADD_OVERFLOW (width, thiswidth))
+ string_overflow ();
+#endif
+ }
+ else if (precision - width < thiswidth)
{
*nchars = i;
*nbytes = i_byte;
@@ -465,7 +476,7 @@
i += chars;
i_byte += bytes;
width += thiswidth;
- }
+ }
if (precision > 0)
{
@@ -672,7 +683,7 @@
}
-/* Convert unibyte text at STR of NBYTES bytes to a multibyte text
+/* Convert unibyte text at STR of BYTES bytes to a multibyte text
that contains the same single-byte characters. It actually
converts all 8-bit characters to multibyte forms. It is assured
that we can use LEN bytes at STR as a work area and that is
@@ -823,7 +834,7 @@
{
if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count
|| (MOST_POSITIVE_FIXNUM - nbytes) / 2 < byte8_count)
- error ("Maximum string size exceeded");
+ string_overflow ();
/* Convert 2-byte sequence of byte8 chars to 4-byte octal. */
val = make_uninit_multibyte_string (nchars + byte8_count * 3,
@@ -832,7 +843,8 @@
else
{
if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count)
- error ("Maximum string size exceeded");
+ string_overflow ();
+
/* Convert 1-byte sequence of byte8 chars to 4-byte octal. */
val = make_uninit_string (nbytes + byte8_count * 3);
}
=== modified file 'src/character.h'
--- a/src/character.h 2011-04-11 03:39:45 +0000
+++ b/src/character.h 2011-05-16 05:08:59 +0000
@@ -612,7 +612,7 @@
extern EMACS_INT strwidth (const char *, EMACS_INT);
extern EMACS_INT c_string_width (const unsigned char *, EMACS_INT, int,
EMACS_INT *, EMACS_INT *);
-extern EMACS_INT lisp_string_width (Lisp_Object, int,
+extern EMACS_INT lisp_string_width (Lisp_Object, EMACS_INT,
EMACS_INT *, EMACS_INT *);
extern Lisp_Object Qcharacterp;
=== modified file 'src/dispextern.h'
--- a/src/dispextern.h 2011-04-23 03:07:16 +0000
+++ b/src/dispextern.h 2011-05-13 01:10:46 +0000
@@ -2709,7 +2709,7 @@
{
/* 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;
=== modified file 'src/fns.c'
--- a/src/fns.c 2011-05-12 07:07:06 +0000
+++ b/src/fns.c 2011-05-15 17:17:44 +0000
@@ -457,10 +457,10 @@
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 @@
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 @@
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 @@
`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.
=== modified file 'src/frame.c'
--- a/src/frame.c 2011-04-19 01:15:59 +0000
+++ b/src/frame.c 2011-05-12 20:23:33 +0000
@@ -1631,7 +1631,7 @@
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 @@
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;
=== modified file 'src/frame.h'
--- a/src/frame.h 2011-05-12 07:07:06 +0000
+++ b/src/frame.h 2011-05-15 17:17:44 +0000
@@ -192,7 +192,7 @@
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. */
=== modified file 'src/image.c'
--- a/src/image.c 2011-05-12 07:07:06 +0000
+++ b/src/image.c 2011-05-15 17:17:44 +0000
@@ -1523,7 +1523,7 @@
{
/* 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)
=== modified file 'src/insdel.c'
--- a/src/insdel.c 2011-04-19 10:48:30 +0000
+++ b/src/insdel.c 2011-05-16 05:15:51 +0000
@@ -20,6 +20,9 @@
#include <config.h>
#include <setjmp.h>
+
+#include <intprops.h>
+
#include "lisp.h"
#include "intervals.h"
#include "buffer.h"
@@ -581,14 +584,19 @@
for (i = 0; i < nbytes; i++)
{
unsigned int c = *ptr++;
+ int n;
if (ASCII_CHAR_P (c))
- outgoing_nbytes++;
+ n = 1;
else
{
c = BYTE8_TO_CHAR (c);
- outgoing_nbytes += CHAR_BYTES (c);
+ n = CHAR_BYTES (c);
}
+
+ if (INT_ADD_OVERFLOW (outgoing_nbytes, n))
+ string_overflow ();
+ outgoing_nbytes += n;
}
return outgoing_nbytes;
=== modified file 'src/keyboard.c'
--- a/src/keyboard.c 2011-05-12 07:07:06 +0000
+++ b/src/keyboard.c 2011-05-15 17:17:44 +0000
@@ -238,7 +238,7 @@
/* 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 @@
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 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 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;
@@ -5556,9 +5556,9 @@
&& (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 @@
&& (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++;
@@ -5987,7 +5987,7 @@
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))
=== modified file 'src/keyboard.h'
--- a/src/keyboard.h 2011-04-14 01:36:53 +0000
+++ b/src/keyboard.h 2011-05-12 20:23:33 +0000
@@ -16,7 +16,7 @@
You should have received a copy of the GNU General Public License
along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
-#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 @@
/* 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;
=== modified file 'src/lisp.h'
--- a/src/lisp.h 2011-05-12 07:07:06 +0000
+++ b/src/lisp.h 2011-05-16 01:11:54 +0000
@@ -470,8 +470,8 @@
#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
@@ -2710,6 +2710,7 @@
EXFUN (Fvector, MANY);
EXFUN (Fmake_symbol, 1);
EXFUN (Fmake_marker, 0);
+extern void string_overflow (void) NO_RETURN;
EXFUN (Fmake_string, 2);
extern Lisp_Object build_string (const char *);
extern Lisp_Object make_string (const char *, EMACS_INT);
=== modified file 'src/menu.c'
--- a/src/menu.c 2011-04-29 17:56:27 +0000
+++ b/src/menu.c 2011-05-12 20:23:33 +0000
@@ -176,6 +176,8 @@
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);
}
@@ -1145,13 +1147,13 @@
#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)
=== modified file 'src/menu.h'
--- a/src/menu.h 2011-01-25 04:08:28 +0000
+++ b/src/menu.h 2011-05-12 20:23:33 +0000
@@ -19,6 +19,8 @@
#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 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 */
-
=== modified file 'src/msdos.c'
--- a/src/msdos.c 2011-04-24 12:48:30 +0000
+++ b/src/msdos.c 2011-05-14 19:06:08 +0000
@@ -287,7 +287,7 @@
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;
=== modified file 'src/nsterm.m'
--- a/src/nsterm.m 2011-04-03 08:30:57 +0000
+++ b/src/nsterm.m 2011-05-14 09:03:53 +0000
@@ -158,7 +158,7 @@
/* 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 @@
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 @@
/* Tell emacs about this window system. */
Fprovide (intern ("ns"), Qnil);
}
-
-
=== modified file 'src/systime.h'
--- a/src/systime.h 2011-03-11 20:24:09 +0000
+++ b/src/systime.h 2011-05-12 20:23:33 +0000
@@ -30,6 +30,12 @@
#endif
#endif
+#ifdef HAVE_X_WINDOWS
+# include <X11/X.h>
+#else
+typedef unsigned long Time;
+#endif
+
#ifdef HAVE_TZNAME
#ifndef tzname /* For SGI. */
extern char *tzname[]; /* RS6000 and others want it this way. */
=== modified file 'src/term.c'
--- a/src/term.c 2011-05-18 00:26:48 +0000
+++ b/src/term.c 2011-05-18 00:39:40 +0000
@@ -2699,9 +2699,10 @@
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;
+ Time sec, usec;
*fp = SELECTED_FRAME ();
(*fp)->mouse_moved = 0;
@@ -2712,7 +2713,9 @@
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.
=== modified file 'src/termhooks.h'
--- a/src/termhooks.h 2011-05-12 07:07:06 +0000
+++ b/src/termhooks.h 2011-05-15 17:17:44 +0000
@@ -20,6 +20,8 @@
/* Miscellanea. */
+#include "systime.h" /* for Time */
+
struct glyph;
struct frame;
@@ -233,7 +235,7 @@
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 @@
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
=== modified file 'src/w32gui.h'
--- a/src/w32gui.h 2011-01-25 04:08:28 +0000
+++ b/src/w32gui.h 2011-05-14 09:03:53 +0000
@@ -20,6 +20,8 @@
#define EMACS_W32GUI_H
#include <windows.h>
+#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 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 @@
#endif /* EMACS_W32GUI_H */
-
=== modified file 'src/w32inevt.c'
--- a/src/w32inevt.c 2011-03-25 15:39:59 +0000
+++ b/src/w32inevt.c 2011-05-14 19:06:08 +0000
@@ -45,7 +45,7 @@
/* 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 @@
enum scroll_bar_part *part,
Lisp_Object *x,
Lisp_Object *y,
- unsigned long *time)
+ Time *time)
{
BLOCK_INPUT;
@@ -756,4 +756,3 @@
UNBLOCK_INPUT;
return ret;
}
-
=== modified file 'src/w32menu.c'
--- a/src/w32menu.c 2011-05-12 07:07:06 +0000
+++ b/src/w32menu.c 2011-05-16 05:17:23 +0000
@@ -146,7 +146,7 @@
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);
=== modified file 'src/window.c'
--- a/src/window.c 2011-05-12 07:07:06 +0000
+++ b/src/window.c 2011-05-15 17:17:44 +0000
@@ -3094,11 +3094,14 @@
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,
=== modified file 'src/xmenu.c'
--- a/src/xmenu.c 2011-05-12 07:07:06 +0000
+++ b/src/xmenu.c 2011-05-15 17:17:44 +0000
@@ -240,7 +240,7 @@
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);
@@ -922,7 +922,7 @@
#endif
Lisp_Object items;
widget_value *wv, *first_wv, *prev_wv = 0;
- EMACS_UINT i, last_i = 0;
+ int i;
int *submenu_start, *submenu_end;
int *submenu_top_level_items, *submenu_n_panes;
@@ -966,7 +966,7 @@
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 @@
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));
@@ -1021,8 +1021,6 @@
{
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 @@
submenu_end[i] = menu_items_used;
}
+ submenu_start[i] = -1;
finish_menu_items ();
/* Convert menu_items into widget_value trees
@@ -1052,7 +1051,7 @@
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],
@@ -1421,7 +1420,8 @@
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;
@@ -1465,7 +1465,7 @@
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));
@@ -1525,7 +1525,7 @@
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];
@@ -1599,7 +1599,7 @@
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;
@@ -2242,7 +2242,7 @@
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;
=== modified file 'src/xselect.c'
--- a/src/xselect.c 2011-05-12 07:07:06 +0000
+++ b/src/xselect.c 2011-05-15 17:17:44 +0000
@@ -121,10 +121,6 @@
#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.
@@ -356,7 +352,7 @@
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);
=== modified file 'src/xterm.c'
--- a/src/xterm.c 2011-05-12 07:07:06 +0000
+++ b/src/xterm.c 2011-05-15 17:17:44 +0000
@@ -342,7 +342,7 @@
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);
@@ -3637,23 +3637,23 @@
/* 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)
@@ -3664,24 +3664,24 @@
| ((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)
@@ -3827,7 +3827,7 @@
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;
@@ -5562,7 +5562,7 @@
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;
=== modified file 'src/xterm.h'
--- a/src/xterm.h 2011-04-16 16:44:58 +0000
+++ b/src/xterm.h 2011-05-11 23:16:52 +0000
@@ -989,8 +989,7 @@
#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 *);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r104265: Int overflow fixes, e.g., string length overflow.,
Paul Eggert <=