diff options
| author | Paul Eggert | 2011-06-17 01:10:34 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-17 01:10:34 -0700 |
| commit | 67c36fce599fc28e5ae3eca371d034c600265dd2 (patch) | |
| tree | d33f388c65d9830ef51ed32a608fd1b523081152 /src/buffer.c | |
| parent | 93cb6be35e90f37078276fe60142050d9cff524a (diff) | |
| download | emacs-67c36fce599fc28e5ae3eca371d034c600265dd2.tar.gz emacs-67c36fce599fc28e5ae3eca371d034c600265dd2.zip | |
* buffer.c (record_overlay_string): Check for size-calculation overflow.
(struct sortstrlist.size, struct sortlist.used): Don't truncate size to int.
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/buffer.c b/src/buffer.c index 90a10ec2a34..93f739c0d4b 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -2933,8 +2933,8 @@ struct sortstr | |||
| 2933 | struct sortstrlist | 2933 | struct sortstrlist |
| 2934 | { | 2934 | { |
| 2935 | struct sortstr *buf; /* An array that expands as needed; never freed. */ | 2935 | struct sortstr *buf; /* An array that expands as needed; never freed. */ |
| 2936 | int size; /* Allocated length of that array. */ | 2936 | ptrdiff_t size; /* Allocated length of that array. */ |
| 2937 | int used; /* How much of the array is currently in use. */ | 2937 | ptrdiff_t used; /* How much of the array is currently in use. */ |
| 2938 | EMACS_INT bytes; /* Total length of the strings in buf. */ | 2938 | EMACS_INT bytes; /* Total length of the strings in buf. */ |
| 2939 | }; | 2939 | }; |
| 2940 | 2940 | ||
| @@ -2969,7 +2969,10 @@ record_overlay_string (struct sortstrlist *ssl, Lisp_Object str, | |||
| 2969 | 2969 | ||
| 2970 | if (ssl->used == ssl->size) | 2970 | if (ssl->used == ssl->size) |
| 2971 | { | 2971 | { |
| 2972 | if (ssl->buf) | 2972 | if (min (PTRDIFF_MAX, SIZE_MAX) / (sizeof (struct sortstr) * 2) |
| 2973 | < ssl->size) | ||
| 2974 | memory_full (SIZE_MAX); | ||
| 2975 | else if (0 < ssl->size) | ||
| 2973 | ssl->size *= 2; | 2976 | ssl->size *= 2; |
| 2974 | else | 2977 | else |
| 2975 | ssl->size = 5; | 2978 | ssl->size = 5; |