From e828765d01313acddcf17279b6b43ae9f777f2a4 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 27 Feb 2019 01:14:27 -0800 Subject: DEFVAR_INT variables are now intmax_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Formerly they were fixnums, which led to problems when dealing with values that might not fit on 32-bit platforms, such as string-chars-consed or floats_consed. 64-bit counters should be good enough for these (for a while, anyway...). While we’re at it, fix some unlikely integer overflow bugs that have been in the code for a while. * lib-src/make-docfile.c (write_globals): * src/data.c (do_symval_forwarding, store_symval_forwarding): * src/eval.c (restore_stack_limits, call_debugger): * src/frame.h (struct frame.cost_calculation_baud_rate): * src/keyboard.c (last_auto_save, bind_polling_period, read_char): * src/lisp.h (struct Lisp_Intfwd.intvar): * src/lread.c (defvar_int): * src/pdumper.c (dump_fwd_int): * src/thread.h (struct thread_state.m_lisp_eval_depth): * src/undo.c (truncate_undo_list): * src/xselect.c (wait_for_property_change) (x_get_foreign_selection): * src/xterm.c (x_emacs_to_x_modifiers): DEFVAR_INT variables now have the C type intmax_t, not EMACS_INT. * src/data.c (store_symval_forwarding): * src/gnutls.c (Fgnutls_boot): * src/keyboard.c (bind_polling_period): * src/macros.c (pop_kbd_macro, Fexecute_kbd_macro): * src/undo.c (truncate_undo_list): Allow any integer that fits into intmax_t, instead of requiring it to be a Lisp fixnum. * src/dispnew.c (update_window): * src/frame.c (x_figure_window_size): * src/gnutls.c (init_gnutls_functions) (emacs_gnutls_handle_error): * src/keyboard.c (make_lisp_event): * src/nsterm.m (ns_dumpglyphs_image): * src/profiler.c (make_log): * src/scroll.c (calculate_scrolling) (calculate_direct_scrolling): * src/termcap.c (tputs): * src/xterm.c (x_draw_image_relief): Avoid implementation-defined behavior on conversion of out-of-range integers. * src/eval.c (when_entered_debugger): Now intmax_t. (max_ensure_room): New function, that avoids signed integer overflow. (call_debugger, signal_or_quit): Use it. * src/fileio.c (Fdo_auto_save): * src/keyboard.c (make_lisp_event): * src/term.c (calculate_costs): * src/xdisp.c (build_desired_tool_bar_string) (hscroll_window_tree, try_scrolling, decode_mode_spec) (x_produce_glyphs): Avoid signed integer overflow. * src/lisp.h (clip_to_bounds): Generalize to intmax_t. * src/pdumper.c (dump_emacs_reloc_immediate_emacs_int): Remove, ... (dump_emacs_reloc_immediate_intmax_t): ... replacing with this function. All uses changed. * src/profiler.c (make_log): Omit args. All callers changed. * src/termcap.c: Include stdlib.h, for atoi. Include intprops.h. * src/window.c (sanitize_next_screen_context_lines): New function. (window_scroll_pixel_based, window_scroll_line_based): Use it to avoid signed integer overflow. --- src/scroll.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/scroll.c') diff --git a/src/scroll.c b/src/scroll.c index e523a19ab89..8eda510945f 100644 --- a/src/scroll.c +++ b/src/scroll.c @@ -107,10 +107,8 @@ calculate_scrolling (struct frame *frame, /* Discourage long scrolls on fast lines. Don't scroll nearly a full frame height unless it saves at least 1/4 second. */ - int extra_cost = baud_rate / (10 * 4 * frame_total_lines); - - if (baud_rate <= 0) - extra_cost = 1; + int extra_cost + = clip_to_bounds (1, baud_rate / (10 * 4) / frame_total_lines, INT_MAX / 2); /* initialize the top left corner of the matrix */ matrix->writecost = 0; @@ -446,10 +444,8 @@ calculate_direct_scrolling (struct frame *frame, /* Discourage long scrolls on fast lines. Don't scroll nearly a full frame height unless it saves at least 1/4 second. */ - int extra_cost = baud_rate / (10 * 4 * frame_total_lines); - - if (baud_rate <= 0) - extra_cost = 1; + int extra_cost + = clip_to_bounds (1, baud_rate / (10 * 4) / frame_total_lines, INT_MAX / 2); /* Overhead of setting the scroll window, plus the extra cost of scrolling by a distance of one. The extra cost is -- cgit v1.2.3