diff options
| author | Paul Eggert | 2019-02-27 01:14:27 -0800 |
|---|---|---|
| committer | Paul Eggert | 2019-02-27 01:23:30 -0800 |
| commit | e828765d01313acddcf17279b6b43ae9f777f2a4 (patch) | |
| tree | 8dd465c5899c62ad5613fe97172fad1ddf419097 /src/termcap.c | |
| parent | 2f7885a4b3609dec19e4595c6c24f3a21f33c5d6 (diff) | |
| download | emacs-e828765d01313acddcf17279b6b43ae9f777f2a4.tar.gz emacs-e828765d01313acddcf17279b6b43ae9f777f2a4.zip | |
DEFVAR_INT variables are now intmax_t
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.
Diffstat (limited to 'src/termcap.c')
| -rw-r--r-- | src/termcap.c | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/src/termcap.c b/src/termcap.c index 2f2a0b29d5e..9e081baa62e 100644 --- a/src/termcap.c +++ b/src/termcap.c | |||
| @@ -20,10 +20,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 20 | 20 | ||
| 21 | /* Emacs config.h may rename various library functions such as malloc. */ | 21 | /* Emacs config.h may rename various library functions such as malloc. */ |
| 22 | #include <config.h> | 22 | #include <config.h> |
| 23 | |||
| 24 | #include <stdlib.h> | ||
| 23 | #include <sys/file.h> | 25 | #include <sys/file.h> |
| 24 | #include <fcntl.h> | 26 | #include <fcntl.h> |
| 25 | #include <unistd.h> | 27 | #include <unistd.h> |
| 26 | 28 | ||
| 29 | #include <intprops.h> | ||
| 30 | |||
| 27 | #include "lisp.h" | 31 | #include "lisp.h" |
| 28 | #include "tparam.h" | 32 | #include "tparam.h" |
| 29 | #ifdef MSDOS | 33 | #ifdef MSDOS |
| @@ -265,14 +269,7 @@ char PC; | |||
| 265 | void | 269 | void |
| 266 | tputs (register const char *str, int nlines, int (*outfun) (int)) | 270 | tputs (register const char *str, int nlines, int (*outfun) (int)) |
| 267 | { | 271 | { |
| 268 | register int padcount = 0; | 272 | int padcount = 0; |
| 269 | register int speed; | ||
| 270 | |||
| 271 | speed = baud_rate; | ||
| 272 | /* For quite high speeds, convert to the smaller | ||
| 273 | units to avoid overflow. */ | ||
| 274 | if (speed > 10000) | ||
| 275 | speed = - speed / 100; | ||
| 276 | 273 | ||
| 277 | if (!str) | 274 | if (!str) |
| 278 | return; | 275 | return; |
| @@ -296,21 +293,13 @@ tputs (register const char *str, int nlines, int (*outfun) (int)) | |||
| 296 | (*outfun) (*str++); | 293 | (*outfun) (*str++); |
| 297 | 294 | ||
| 298 | /* PADCOUNT is now in units of tenths of msec. | 295 | /* PADCOUNT is now in units of tenths of msec. |
| 299 | SPEED is measured in characters per 10 seconds | 296 | BAUD_RATE is measured in characters per 10 seconds. |
| 300 | or in characters per .1 seconds (if negative). | 297 | Compute PADFACTOR = 100000 * (how many padding bytes are needed). */ |
| 301 | We use the smaller units for larger speeds to avoid overflow. */ | 298 | intmax_t padfactor; |
| 302 | padcount *= speed; | 299 | if (INT_MULTIPLY_WRAPV (padcount, baud_rate, &padfactor)) |
| 303 | padcount += 500; | 300 | padfactor = baud_rate < 0 ? INTMAX_MIN : INTMAX_MAX; |
| 304 | padcount /= 1000; | ||
| 305 | if (speed < 0) | ||
| 306 | padcount = -padcount; | ||
| 307 | else | ||
| 308 | { | ||
| 309 | padcount += 50; | ||
| 310 | padcount /= 100; | ||
| 311 | } | ||
| 312 | 301 | ||
| 313 | while (padcount-- > 0) | 302 | for (; 50000 <= padfactor; padfactor -= 100000) |
| 314 | (*outfun) (PC); | 303 | (*outfun) (PC); |
| 315 | } | 304 | } |
| 316 | 305 | ||
| @@ -426,7 +415,7 @@ tgetent (char *bp, const char *name) | |||
| 426 | } | 415 | } |
| 427 | 416 | ||
| 428 | if (!termcap_name || !filep) | 417 | if (!termcap_name || !filep) |
| 429 | termcap_name = TERMCAP_FILE; | 418 | termcap_name = (char *) TERMCAP_FILE; |
| 430 | 419 | ||
| 431 | /* Here we know we must search a file and termcap_name has its name. */ | 420 | /* Here we know we must search a file and termcap_name has its name. */ |
| 432 | 421 | ||