diff options
| author | Paul Eggert | 2011-06-20 18:21:44 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-20 18:21:44 -0700 |
| commit | 4eab31dd61e80ac5b38b964c91577e0c855e1432 (patch) | |
| tree | d471e0b381abd668de51d86cb6f8c85dd07b4ea6 /src | |
| parent | 25c7e41fc6c1af7ab718abb7dee7964bafe2e17a (diff) | |
| download | emacs-4eab31dd61e80ac5b38b964c91577e0c855e1432.tar.gz emacs-4eab31dd61e80ac5b38b964c91577e0c855e1432.zip | |
* 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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | 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 @@ | |||
| 1 | 2011-06-21 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-06-21 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * xdisp.c (message_log_check_duplicate): Return intmax_t, | ||
| 4 | not unsigned long, as we prefer signed integers. All callers changed. | ||
| 5 | Detect integer overflow in repeat count. | ||
| 6 | (message_dolog): Don't assume print length fits in 39 bytes. | ||
| 7 | |||
| 3 | * termcap.c: Don't assume sizes fit in int and never overflow. | 8 | * termcap.c: Don't assume sizes fit in int and never overflow. |
| 4 | (struct termcap_buffer, tgetent): Use ptrdiff_t, not int, for sizes. | 9 | (struct termcap_buffer, tgetent): Use ptrdiff_t, not int, for sizes. |
| 5 | (gobble_line): Check for size-calculation overflow. | 10 | (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); | |||
| 810 | static int try_scrolling (Lisp_Object, int, EMACS_INT, EMACS_INT, int, int); | 810 | static int try_scrolling (Lisp_Object, int, EMACS_INT, EMACS_INT, int, int); |
| 811 | static int try_cursor_movement (Lisp_Object, struct text_pos, int *); | 811 | static int try_cursor_movement (Lisp_Object, struct text_pos, int *); |
| 812 | static int trailing_whitespace_p (EMACS_INT); | 812 | static int trailing_whitespace_p (EMACS_INT); |
| 813 | static unsigned long int message_log_check_duplicate (EMACS_INT, EMACS_INT); | 813 | static intmax_t message_log_check_duplicate (EMACS_INT, EMACS_INT); |
| 814 | static void push_it (struct it *, struct text_pos *); | 814 | static void push_it (struct it *, struct text_pos *); |
| 815 | static void pop_it (struct it *); | 815 | static void pop_it (struct it *); |
| 816 | static void sync_frame_with_window_matrix_rows (struct window *); | 816 | 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) | |||
| 8064 | if (nlflag) | 8064 | if (nlflag) |
| 8065 | { | 8065 | { |
| 8066 | EMACS_INT this_bol, this_bol_byte, prev_bol, prev_bol_byte; | 8066 | EMACS_INT this_bol, this_bol_byte, prev_bol, prev_bol_byte; |
| 8067 | unsigned long int dups; | 8067 | intmax_t dups; |
| 8068 | insert_1 ("\n", 1, 1, 0, 0); | 8068 | insert_1 ("\n", 1, 1, 0, 0); |
| 8069 | 8069 | ||
| 8070 | scan_newline (Z, Z_BYTE, BEG, BEG_BYTE, -2, 0); | 8070 | 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) | |||
| 8087 | this_bol, this_bol_byte, 0); | 8087 | this_bol, this_bol_byte, 0); |
| 8088 | if (dups > 1) | 8088 | if (dups > 1) |
| 8089 | { | 8089 | { |
| 8090 | char dupstr[40]; | 8090 | char dupstr[sizeof " [ times]" |
| 8091 | + INT_STRLEN_BOUND (intmax_t)]; | ||
| 8091 | int duplen; | 8092 | int duplen; |
| 8092 | 8093 | ||
| 8093 | /* If you change this format, don't forget to also | 8094 | /* If you change this format, don't forget to also |
| 8094 | change message_log_check_duplicate. */ | 8095 | change message_log_check_duplicate. */ |
| 8095 | sprintf (dupstr, " [%lu times]", dups); | 8096 | sprintf (dupstr, " [%"PRIdMAX" times]", dups); |
| 8096 | duplen = strlen (dupstr); | 8097 | duplen = strlen (dupstr); |
| 8097 | TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1); | 8098 | TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1); |
| 8098 | insert_1 (dupstr, duplen, 1, 0, 1); | 8099 | insert_1 (dupstr, duplen, 1, 0, 1); |
| @@ -8154,7 +8155,7 @@ message_dolog (const char *m, EMACS_INT nbytes, int nlflag, int multibyte) | |||
| 8154 | Return 0 if different, 1 if the new one should just replace it, or a | 8155 | Return 0 if different, 1 if the new one should just replace it, or a |
| 8155 | value N > 1 if we should also append " [N times]". */ | 8156 | value N > 1 if we should also append " [N times]". */ |
| 8156 | 8157 | ||
| 8157 | static unsigned long int | 8158 | static intmax_t |
| 8158 | message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte) | 8159 | message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte) |
| 8159 | { | 8160 | { |
| 8160 | EMACS_INT i; | 8161 | EMACS_INT i; |
| @@ -8176,8 +8177,8 @@ message_log_check_duplicate (EMACS_INT prev_bol_byte, EMACS_INT this_bol_byte) | |||
| 8176 | if (*p1++ == ' ' && *p1++ == '[') | 8177 | if (*p1++ == ' ' && *p1++ == '[') |
| 8177 | { | 8178 | { |
| 8178 | char *pend; | 8179 | char *pend; |
| 8179 | unsigned long int n = strtoul ((char *) p1, &pend, 10); | 8180 | intmax_t n = strtoimax ((char *) p1, &pend, 10); |
| 8180 | if (strncmp (pend, " times]\n", 8) == 0) | 8181 | if (0 < n && n < INTMAX_MAX && strncmp (pend, " times]\n", 8) == 0) |
| 8181 | return n+1; | 8182 | return n+1; |
| 8182 | } | 8183 | } |
| 8183 | return 0; | 8184 | return 0; |