* image.c (png_load): Don't assume height * row_bytes fits in 'int'.
- * bidi.c (bidi_dump_cached_states): Use pD to print ptrdiff_t.
-
* xfaces.c (Fbitmap_spec_p): Fix integer overflow bug.
Without this fix, (bitmap-spec-p '(34359738368 1 "x"))
would wrongly return t on a 64-bit host.
Use ptrdiff_t rather than size_t when either will do, as we prefer
signed integers.
- * bidi.c: Integer signedness and overflow fixes.
- (bidi_cache_idx, bidi_cache_last_idx, bidi_cache_fetch_state)
- (bidi_cache_search, bidi_cache_find_level_change)
- (bidi_cache_iterator_state, bidi_cache_find)
- (bidi_find_other_level_edge, bidi_dump_cached_states):
- Don't arbitrarily limit cache indexes to int; use ptrdiff_t instead.
- (bidi_cache_size): Use ptrdiff_t rather than size_t, as we prefer
- signed integers.
- (elsz): Make it a (signed) constant.
- (bidi_cache_iterator_state): Check for size-calculation overflow.
-
* alloc.c: Integer signedness and overflow fixes.
Do not impose an arbitrary 32-bit limit on malloc sizes when debugging.
(__malloc_size_t): Default to size_t, not to int.
#define BIDI_CACHE_CHUNK 200
static struct bidi_it *bidi_cache;
-static ptrdiff_t bidi_cache_size = 0;
-enum { elsz = sizeof (struct bidi_it) };
-static ptrdiff_t bidi_cache_idx; /* next unused cache slot */
-static ptrdiff_t bidi_cache_last_idx; /* slot of last cache hit */
+static size_t bidi_cache_size = 0;
+static size_t elsz = sizeof (struct bidi_it);
+static int bidi_cache_idx; /* next unused cache slot */
+static int bidi_cache_last_idx; /* slot of last cache hit */
static inline void
bidi_cache_reset (void)
}
static inline void
-bidi_cache_fetch_state (ptrdiff_t idx, struct bidi_it *bidi_it)
+bidi_cache_fetch_state (int idx, struct bidi_it *bidi_it)
{
int current_scan_dir = bidi_it->scan_dir;
level less or equal to LEVEL. if LEVEL is -1, disregard the
resolved levels in cached states. DIR, if non-zero, means search
in that direction from the last cache hit. */
-static inline ptrdiff_t
+static inline int
bidi_cache_search (EMACS_INT charpos, int level, int dir)
{
- ptrdiff_t i, i_start;
+ int i, i_start;
if (bidi_cache_idx)
{
C, searching backwards (DIR = -1) for LEVEL = 2 will return the
index of slot B or A, depending whether BEFORE is, respectively,
non-zero or zero. */
-static ptrdiff_t
+static int
bidi_cache_find_level_change (int level, int dir, int before)
{
if (bidi_cache_idx)
{
- ptrdiff_t i = dir ? bidi_cache_last_idx : bidi_cache_idx - 1;
+ int i = dir ? bidi_cache_last_idx : bidi_cache_idx - 1;
int incr = before ? 1 : 0;
if (!dir)
static inline void
bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved)
{
- ptrdiff_t idx;
+ int idx;
/* We should never cache on backward scans. */
if (bidi_it->scan_dir == -1)
/* Enlarge the cache as needed. */
if (idx >= bidi_cache_size)
{
- if (min (PTRDIFF_MAX, SIZE_MAX) / elsz - BIDI_CACHE_CHUNK
- < bidi_cache_size)
- memory_full (SIZE_MAX);
bidi_cache_size += BIDI_CACHE_CHUNK;
bidi_cache =
(struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size * elsz);
static inline bidi_type_t
bidi_cache_find (EMACS_INT charpos, int level, struct bidi_it *bidi_it)
{
- ptrdiff_t i = bidi_cache_search (charpos, level, bidi_it->scan_dir);
+ int i = bidi_cache_search (charpos, level, bidi_it->scan_dir);
if (i >= 0)
{
bidi_find_other_level_edge (struct bidi_it *bidi_it, int level, int end_flag)
{
int dir = end_flag ? -bidi_it->scan_dir : bidi_it->scan_dir;
- ptrdiff_t idx;
+ int idx;
/* Try the cache first. */
if ((idx = bidi_cache_find_level_change (level, dir, end_flag)) >= 0)
void
bidi_dump_cached_states (void)
{
- ptrdiff_t i;
+ int i;
int ndigits = 1;
if (bidi_cache_idx == 0)
fprintf (stderr, "The cache is empty.\n");
return;
}
- fprintf (stderr, "Total of %"pD"d state%s in cache:\n",
+ fprintf (stderr, "Total of %d state%s in cache:\n",
bidi_cache_idx, bidi_cache_idx == 1 ? "" : "s");
for (i = bidi_cache[bidi_cache_idx - 1].charpos; i > 0; i /= 10)