diff options
| author | Paul Eggert | 2011-07-28 18:04:51 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-28 18:04:51 -0700 |
| commit | 1ef7689b9784baa31d1d723909d226fddd95bc86 (patch) | |
| tree | de24def9f1fbd9c6f4820b5c4515682081b7f645 /src | |
| parent | ea8a7d00f9678471e960117b0b87318dcf4e7d81 (diff) | |
| download | emacs-1ef7689b9784baa31d1d723909d226fddd95bc86.tar.gz emacs-1ef7689b9784baa31d1d723909d226fddd95bc86.zip | |
* nsterm.h (struct ns_color_table.size, struct ns_color_table.avail):
Now ptrdiff_t, not int.
* nsterm.m (ns_index_color): Use ptrdiff_t, not int, for table indexes.
(ns_draw_fringe_bitmap): Rewrite to avoid overflow.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | src/nsterm.h | 4 | ||||
| -rw-r--r-- | src/nsterm.m | 21 |
3 files changed, 21 insertions, 9 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 4e10537edc8..748ccc333b2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | 2011-07-29 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-07-29 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * nsterm.h (struct ns_color_table.size, struct ns_color_table.avail): | ||
| 4 | Now ptrdiff_t, not int. | ||
| 5 | * nsterm.m (ns_index_color): Use ptrdiff_t, not int, for table indexes. | ||
| 6 | (ns_draw_fringe_bitmap): Rewrite to avoid overflow. | ||
| 7 | |||
| 3 | * minibuf.c (read_minibuf_noninteractive): Don't leak memory | 8 | * minibuf.c (read_minibuf_noninteractive): Don't leak memory |
| 4 | on memory overflow. | 9 | on memory overflow. |
| 5 | 10 | ||
diff --git a/src/nsterm.h b/src/nsterm.h index f419391a11e..17003ac947b 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -416,8 +416,8 @@ struct ns_bitmap_record | |||
| 416 | /* this to map between emacs color indices and NSColor objects */ | 416 | /* this to map between emacs color indices and NSColor objects */ |
| 417 | struct ns_color_table | 417 | struct ns_color_table |
| 418 | { | 418 | { |
| 419 | unsigned int size; | 419 | ptrdiff_t size; |
| 420 | unsigned int avail; | 420 | ptrdiff_t avail; |
| 421 | #ifdef __OBJC__ | 421 | #ifdef __OBJC__ |
| 422 | NSColor **colors; | 422 | NSColor **colors; |
| 423 | NSMutableSet *empty_indices; | 423 | NSMutableSet *empty_indices; |
diff --git a/src/nsterm.m b/src/nsterm.m index 546247ab74a..4fb9a8e8f61 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -1343,7 +1343,7 @@ unsigned long | |||
| 1343 | ns_index_color (NSColor *color, struct frame *f) | 1343 | ns_index_color (NSColor *color, struct frame *f) |
| 1344 | { | 1344 | { |
| 1345 | struct ns_color_table *color_table = FRAME_NS_DISPLAY_INFO (f)->color_table; | 1345 | struct ns_color_table *color_table = FRAME_NS_DISPLAY_INFO (f)->color_table; |
| 1346 | int idx; | 1346 | ptrdiff_t idx; |
| 1347 | NSNumber *index; | 1347 | NSNumber *index; |
| 1348 | 1348 | ||
| 1349 | if (!color_table->colors) | 1349 | if (!color_table->colors) |
| @@ -1358,7 +1358,7 @@ ns_index_color (NSColor *color, struct frame *f) | |||
| 1358 | 1358 | ||
| 1359 | /* do we already have this color ? */ | 1359 | /* do we already have this color ? */ |
| 1360 | { | 1360 | { |
| 1361 | int i; | 1361 | ptrdiff_t i; |
| 1362 | for (i = 1; i < color_table->avail; i++) | 1362 | for (i = 1; i < color_table->avail; i++) |
| 1363 | { | 1363 | { |
| 1364 | if (color_table->colors[i] && [color_table->colors[i] isEqual: color]) | 1364 | if (color_table->colors[i] && [color_table->colors[i] isEqual: color]) |
| @@ -1373,16 +1373,23 @@ ns_index_color (NSColor *color, struct frame *f) | |||
| 1373 | { | 1373 | { |
| 1374 | index = [color_table->empty_indices anyObject]; | 1374 | index = [color_table->empty_indices anyObject]; |
| 1375 | [color_table->empty_indices removeObject: index]; | 1375 | [color_table->empty_indices removeObject: index]; |
| 1376 | idx = [index unsignedIntValue]; | 1376 | idx = [index unsignedLongValue]; |
| 1377 | } | 1377 | } |
| 1378 | else | 1378 | else |
| 1379 | { | 1379 | { |
| 1380 | if (color_table->avail == color_table->size) | 1380 | if (color_table->avail == color_table->size) |
| 1381 | { | 1381 | { |
| 1382 | color_table->size += NS_COLOR_CAPACITY; | 1382 | ptrdiff_t size; |
| 1383 | ptrdiff_t size_max = | ||
| 1384 | min (ULONG_MAX, | ||
| 1385 | min (PTRDIFF_MAX, SIZE_MAX) / sizeof (NSColor *)); | ||
| 1386 | if (size_max - NS_COLOR_CAPACITY < color_table->size) | ||
| 1387 | memory_full (SIZE_MAX); | ||
| 1388 | size = color_table->size + NS_COLOR_CAPACITY; | ||
| 1383 | color_table->colors | 1389 | color_table->colors |
| 1384 | = (NSColor **)xrealloc (color_table->colors, | 1390 | = (NSColor **)xrealloc (color_table->colors, |
| 1385 | color_table->size * sizeof (NSColor *)); | 1391 | size * sizeof (NSColor *)); |
| 1392 | color_table->size = size; | ||
| 1386 | } | 1393 | } |
| 1387 | idx = color_table->avail++; | 1394 | idx = color_table->avail++; |
| 1388 | } | 1395 | } |
| @@ -2323,7 +2330,7 @@ ns_draw_fringe_bitmap (struct window *w, struct glyph_row *row, | |||
| 2323 | if (!img) | 2330 | if (!img) |
| 2324 | { | 2331 | { |
| 2325 | unsigned short *bits = p->bits + p->dh; | 2332 | unsigned short *bits = p->bits + p->dh; |
| 2326 | int len = 8 * p->h/8; | 2333 | int len = p->h; |
| 2327 | int i; | 2334 | int i; |
| 2328 | unsigned char *cbits = xmalloc (len); | 2335 | unsigned char *cbits = xmalloc (len); |
| 2329 | 2336 | ||
| @@ -4705,7 +4712,7 @@ ns_term_shutdown (int sig) | |||
| 4705 | } | 4712 | } |
| 4706 | } | 4713 | } |
| 4707 | 4714 | ||
| 4708 | 4715 | ||
| 4709 | #if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 | 4716 | #if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 |
| 4710 | /* if we get here we should send the key for input manager processing */ | 4717 | /* if we get here we should send the key for input manager processing */ |
| 4711 | if (firstTime && [[NSInputManager currentInputManager] | 4718 | if (firstTime && [[NSInputManager currentInputManager] |