diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2011-05-15 22:15:51 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2011-05-15 22:15:51 -0700 |
commit | 06d6db334ef501be6280e950b9158c539c24eb4d (patch) | |
tree | ce31b6356d354490a2bbc9b07c804abc1a804d33 /src/insdel.c | |
parent | 2b4560a850d2ea0767d0a3c4db19e4468f61b4eb (diff) | |
download | emacs-06d6db334ef501be6280e950b9158c539c24eb4d.tar.gz |
* insdel.c (count_size_as_multibyte): Check for string overflow.
Diffstat (limited to 'src/insdel.c')
-rw-r--r-- | src/insdel.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/insdel.c b/src/insdel.c index 2662858c2a1..de9e8aa570a 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -20,6 +20,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <setjmp.h> + +#include <intprops.h> + #include "lisp.h" #include "intervals.h" #include "buffer.h" @@ -581,14 +584,19 @@ count_size_as_multibyte (const unsigned char *ptr, EMACS_INT nbytes) 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; |