From 4eab31dd61e80ac5b38b964c91577e0c855e1432 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 20 Jun 2011 18:21:44 -0700 Subject: [PATCH] * xdisp.c (message_log_check_duplicate): Return intmax_t, not unsigned long, as we prefer signed integers. All callers changed. Detect integer overflow in repeat count. (message_dolog): Don't assume print length fits in 39 bytes. --- src/ChangeLog | 5 +++++ src/xdisp.c | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 210f4f6bd60..bcff6fd0831 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2011-06-21 Paul Eggert + * xdisp.c (message_log_check_duplicate): Return intmax_t, + not unsigned long, as we prefer signed integers. All callers changed. + Detect integer overflow in repeat count. + (message_dolog): Don't assume print length fits in 39 bytes. + * termcap.c: Don't assume sizes fit in int and never overflow. (struct termcap_buffer, tgetent): Use ptrdiff_t, not int, for sizes. (gobble_line): Check for size-calculation overflow. diff --git a/src/xdisp.c b/src/xdisp.c index e985ef9ae4e..ce60b658a73 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -810,7 +810,7 @@ static int cursor_row_fully_visible_p (struct window *, int, int); static int try_scrolling (Lisp_Object, int, EMACS_INT, EMACS_INT, int, int); static int try_cursor_movement (Lisp_Object, struct text_pos, int *); static int trailing_whitespace_p (EMACS_INT); -static unsigned long int message_log_check_duplicate (EMACS_INT, EMACS_INT); +static intmax_t message_log_check_duplicate (EMACS_INT, EMACS_INT); static void push_it (struct it *, struct text_pos *); static void pop_it (struct it *); static void sync_frame_with_window_matrix_rows (struct window *); @@ -8064,7 +8064,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte) if (nlflag) { EMACS_INT this_bol, this_bol_byte, prev_bol, prev_bol_byte; - unsigned long int dups; + intmax_t dups; insert_1 ("\n", 1, 1, 0, 0); scan_newline (Z, Z_BYTE, BEG, BEG_BYTE, -2, 0); @@ -8087,12 +8087,13 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte) this_bol, this_bol_byte, 0); if (dups > 1) { - char dupstr[40]; + char dupstr[sizeof " [ times]" + + INT_STRLEN_BOUND (intmax_t)]; int duplen; /* If you change this format, don't forget to also change message_log_check_duplicate. */ - sprintf (dupstr, " [%lu times]", dups); + sprintf (dupstr, " [%"PRIdMAX" times]", dups); duplen = strlen (dupstr); TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1); insert_1 (dupstr, duplen, 1, 0, 1); @@ -8154,7 +8155,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte) Return 0 if different, 1 if the new one should just replace it, or a value N > 1 if we should also append " [N times]". */ -static unsigned long int +static intmax_t message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte) { EMACS_INT i; @@ -8176,8 +8177,8 @@ message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte) if (*p1++ == ' ' && *p1++ == '[') { char *pend; - unsigned long int n = strtoul ((char *) p1, &pend, 10); - if (strncmp (pend, " times]\n", 8) == 0) + intmax_t n = strtoimax ((char *) p1, &pend, 10); + if (0 < n && n < INTMAX_MAX && strncmp (pend, " times]\n", 8) == 0) return n+1; } return 0; -- 2.11.4.GIT