diff options
| author | Paul Eggert | 2011-07-14 09:20:47 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-14 09:20:47 -0700 |
| commit | af1d7677299425547ec39d20810890333a9970a7 (patch) | |
| tree | 17518881b6947d3fb8f1e9905ddb8e80ced25c9c /src | |
| parent | 5023daec057b530a4dcd64d6fc6a3c2e36b925a5 (diff) | |
| download | emacs-af1d7677299425547ec39d20810890333a9970a7.tar.gz emacs-af1d7677299425547ec39d20810890333a9970a7.zip | |
* src/bidi.c: Hold off on these changes for now.
See <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9079#11>.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 13 | ||||
| -rw-r--r-- | src/bidi.c | 31 |
2 files changed, 14 insertions, 30 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index e0de5edda9c..0977b12ab38 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -31,8 +31,6 @@ | |||
| 31 | 31 | ||
| 32 | * image.c (png_load): Don't assume height * row_bytes fits in 'int'. | 32 | * image.c (png_load): Don't assume height * row_bytes fits in 'int'. |
| 33 | 33 | ||
| 34 | * bidi.c (bidi_dump_cached_states): Use pD to print ptrdiff_t. | ||
| 35 | |||
| 36 | * xfaces.c (Fbitmap_spec_p): Fix integer overflow bug. | 34 | * xfaces.c (Fbitmap_spec_p): Fix integer overflow bug. |
| 37 | Without this fix, (bitmap-spec-p '(34359738368 1 "x")) | 35 | Without this fix, (bitmap-spec-p '(34359738368 1 "x")) |
| 38 | would wrongly return t on a 64-bit host. | 36 | would wrongly return t on a 64-bit host. |
| @@ -116,17 +114,6 @@ | |||
| 116 | Use ptrdiff_t rather than size_t when either will do, as we prefer | 114 | Use ptrdiff_t rather than size_t when either will do, as we prefer |
| 117 | signed integers. | 115 | signed integers. |
| 118 | 116 | ||
| 119 | * bidi.c: Integer signedness and overflow fixes. | ||
| 120 | (bidi_cache_idx, bidi_cache_last_idx, bidi_cache_fetch_state) | ||
| 121 | (bidi_cache_search, bidi_cache_find_level_change) | ||
| 122 | (bidi_cache_iterator_state, bidi_cache_find) | ||
| 123 | (bidi_find_other_level_edge, bidi_dump_cached_states): | ||
| 124 | Don't arbitrarily limit cache indexes to int; use ptrdiff_t instead. | ||
| 125 | (bidi_cache_size): Use ptrdiff_t rather than size_t, as we prefer | ||
| 126 | signed integers. | ||
| 127 | (elsz): Make it a (signed) constant. | ||
| 128 | (bidi_cache_iterator_state): Check for size-calculation overflow. | ||
| 129 | |||
| 130 | * alloc.c: Integer signedness and overflow fixes. | 117 | * alloc.c: Integer signedness and overflow fixes. |
| 131 | Do not impose an arbitrary 32-bit limit on malloc sizes when debugging. | 118 | Do not impose an arbitrary 32-bit limit on malloc sizes when debugging. |
| 132 | (__malloc_size_t): Default to size_t, not to int. | 119 | (__malloc_size_t): Default to size_t, not to int. |
diff --git a/src/bidi.c b/src/bidi.c index 2662ee3d845..469afdb3819 100644 --- a/src/bidi.c +++ b/src/bidi.c | |||
| @@ -263,10 +263,10 @@ bidi_copy_it (struct bidi_it *to, struct bidi_it *from) | |||
| 263 | 263 | ||
| 264 | #define BIDI_CACHE_CHUNK 200 | 264 | #define BIDI_CACHE_CHUNK 200 |
| 265 | static struct bidi_it *bidi_cache; | 265 | static struct bidi_it *bidi_cache; |
| 266 | static ptrdiff_t bidi_cache_size = 0; | 266 | static size_t bidi_cache_size = 0; |
| 267 | enum { elsz = sizeof (struct bidi_it) }; | 267 | static size_t elsz = sizeof (struct bidi_it); |
| 268 | static ptrdiff_t bidi_cache_idx; /* next unused cache slot */ | 268 | static int bidi_cache_idx; /* next unused cache slot */ |
| 269 | static ptrdiff_t bidi_cache_last_idx; /* slot of last cache hit */ | 269 | static int bidi_cache_last_idx; /* slot of last cache hit */ |
| 270 | 270 | ||
| 271 | static inline void | 271 | static inline void |
| 272 | bidi_cache_reset (void) | 272 | bidi_cache_reset (void) |
| @@ -288,7 +288,7 @@ bidi_cache_shrink (void) | |||
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | static inline void | 290 | static inline void |
| 291 | bidi_cache_fetch_state (ptrdiff_t idx, struct bidi_it *bidi_it) | 291 | bidi_cache_fetch_state (int idx, struct bidi_it *bidi_it) |
| 292 | { | 292 | { |
| 293 | int current_scan_dir = bidi_it->scan_dir; | 293 | int current_scan_dir = bidi_it->scan_dir; |
| 294 | 294 | ||
| @@ -304,10 +304,10 @@ bidi_cache_fetch_state (ptrdiff_t idx, struct bidi_it *bidi_it) | |||
| 304 | level less or equal to LEVEL. if LEVEL is -1, disregard the | 304 | level less or equal to LEVEL. if LEVEL is -1, disregard the |
| 305 | resolved levels in cached states. DIR, if non-zero, means search | 305 | resolved levels in cached states. DIR, if non-zero, means search |
| 306 | in that direction from the last cache hit. */ | 306 | in that direction from the last cache hit. */ |
| 307 | static inline ptrdiff_t | 307 | static inline int |
| 308 | bidi_cache_search (EMACS_INT charpos, int level, int dir) | 308 | bidi_cache_search (EMACS_INT charpos, int level, int dir) |
| 309 | { | 309 | { |
| 310 | ptrdiff_t i, i_start; | 310 | int i, i_start; |
| 311 | 311 | ||
| 312 | if (bidi_cache_idx) | 312 | if (bidi_cache_idx) |
| 313 | { | 313 | { |
| @@ -366,12 +366,12 @@ bidi_cache_search (EMACS_INT charpos, int level, int dir) | |||
| 366 | C, searching backwards (DIR = -1) for LEVEL = 2 will return the | 366 | C, searching backwards (DIR = -1) for LEVEL = 2 will return the |
| 367 | index of slot B or A, depending whether BEFORE is, respectively, | 367 | index of slot B or A, depending whether BEFORE is, respectively, |
| 368 | non-zero or zero. */ | 368 | non-zero or zero. */ |
| 369 | static ptrdiff_t | 369 | static int |
| 370 | bidi_cache_find_level_change (int level, int dir, int before) | 370 | bidi_cache_find_level_change (int level, int dir, int before) |
| 371 | { | 371 | { |
| 372 | if (bidi_cache_idx) | 372 | if (bidi_cache_idx) |
| 373 | { | 373 | { |
| 374 | ptrdiff_t i = dir ? bidi_cache_last_idx : bidi_cache_idx - 1; | 374 | int i = dir ? bidi_cache_last_idx : bidi_cache_idx - 1; |
| 375 | int incr = before ? 1 : 0; | 375 | int incr = before ? 1 : 0; |
| 376 | 376 | ||
| 377 | if (!dir) | 377 | if (!dir) |
| @@ -407,7 +407,7 @@ bidi_cache_find_level_change (int level, int dir, int before) | |||
| 407 | static inline void | 407 | static inline void |
| 408 | bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved) | 408 | bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved) |
| 409 | { | 409 | { |
| 410 | ptrdiff_t idx; | 410 | int idx; |
| 411 | 411 | ||
| 412 | /* We should never cache on backward scans. */ | 412 | /* We should never cache on backward scans. */ |
| 413 | if (bidi_it->scan_dir == -1) | 413 | if (bidi_it->scan_dir == -1) |
| @@ -420,9 +420,6 @@ bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved) | |||
| 420 | /* Enlarge the cache as needed. */ | 420 | /* Enlarge the cache as needed. */ |
| 421 | if (idx >= bidi_cache_size) | 421 | if (idx >= bidi_cache_size) |
| 422 | { | 422 | { |
| 423 | if (min (PTRDIFF_MAX, SIZE_MAX) / elsz - BIDI_CACHE_CHUNK | ||
| 424 | < bidi_cache_size) | ||
| 425 | memory_full (SIZE_MAX); | ||
| 426 | bidi_cache_size += BIDI_CACHE_CHUNK; | 423 | bidi_cache_size += BIDI_CACHE_CHUNK; |
| 427 | bidi_cache = | 424 | bidi_cache = |
| 428 | (struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size * elsz); | 425 | (struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size * elsz); |
| @@ -471,7 +468,7 @@ bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved) | |||
| 471 | static inline bidi_type_t | 468 | static inline bidi_type_t |
| 472 | bidi_cache_find (EMACS_INT charpos, int level, struct bidi_it *bidi_it) | 469 | bidi_cache_find (EMACS_INT charpos, int level, struct bidi_it *bidi_it) |
| 473 | { | 470 | { |
| 474 | ptrdiff_t i = bidi_cache_search (charpos, level, bidi_it->scan_dir); | 471 | int i = bidi_cache_search (charpos, level, bidi_it->scan_dir); |
| 475 | 472 | ||
| 476 | if (i >= 0) | 473 | if (i >= 0) |
| 477 | { | 474 | { |
| @@ -1759,7 +1756,7 @@ static void | |||
| 1759 | bidi_find_other_level_edge (struct bidi_it *bidi_it, int level, int end_flag) | 1756 | bidi_find_other_level_edge (struct bidi_it *bidi_it, int level, int end_flag) |
| 1760 | { | 1757 | { |
| 1761 | int dir = end_flag ? -bidi_it->scan_dir : bidi_it->scan_dir; | 1758 | int dir = end_flag ? -bidi_it->scan_dir : bidi_it->scan_dir; |
| 1762 | ptrdiff_t idx; | 1759 | int idx; |
| 1763 | 1760 | ||
| 1764 | /* Try the cache first. */ | 1761 | /* Try the cache first. */ |
| 1765 | if ((idx = bidi_cache_find_level_change (level, dir, end_flag)) >= 0) | 1762 | if ((idx = bidi_cache_find_level_change (level, dir, end_flag)) >= 0) |
| @@ -1915,7 +1912,7 @@ void bidi_dump_cached_states (void) EXTERNALLY_VISIBLE; | |||
| 1915 | void | 1912 | void |
| 1916 | bidi_dump_cached_states (void) | 1913 | bidi_dump_cached_states (void) |
| 1917 | { | 1914 | { |
| 1918 | ptrdiff_t i; | 1915 | int i; |
| 1919 | int ndigits = 1; | 1916 | int ndigits = 1; |
| 1920 | 1917 | ||
| 1921 | if (bidi_cache_idx == 0) | 1918 | if (bidi_cache_idx == 0) |
| @@ -1923,7 +1920,7 @@ bidi_dump_cached_states (void) | |||
| 1923 | fprintf (stderr, "The cache is empty.\n"); | 1920 | fprintf (stderr, "The cache is empty.\n"); |
| 1924 | return; | 1921 | return; |
| 1925 | } | 1922 | } |
| 1926 | fprintf (stderr, "Total of %"pD"d state%s in cache:\n", | 1923 | fprintf (stderr, "Total of %d state%s in cache:\n", |
| 1927 | bidi_cache_idx, bidi_cache_idx == 1 ? "" : "s"); | 1924 | bidi_cache_idx, bidi_cache_idx == 1 ? "" : "s"); |
| 1928 | 1925 | ||
| 1929 | for (i = bidi_cache[bidi_cache_idx - 1].charpos; i > 0; i /= 10) | 1926 | for (i = bidi_cache[bidi_cache_idx - 1].charpos; i > 0; i /= 10) |