RTL characters in the offending line of text. */
/* Do we need to allow customization of this limit? */
#define BIDI_CACHE_MAX_ELTS_PER_SLOT 50000
-#if BIDI_CACHE_CHUNK >= BIDI_CACHE_MAX_ELTS_PER_SLOT
-# error BIDI_CACHE_CHUNK must be less than BIDI_CACHE_MAX_ELTS_PER_SLOT
-#endif
+verify (BIDI_CACHE_CHUNK < BIDI_CACHE_MAX_ELTS_PER_SLOT);
static ptrdiff_t bidi_cache_max_elts = BIDI_CACHE_MAX_ELTS_PER_SLOT;
static struct bidi_it *bidi_cache;
static ptrdiff_t bidi_cache_size = 0;
unsigned flags : 2;
} bpa_stack_entry;
-/* With MAX_ALLOCA of 16KB, this should allow at least 1K slots in the
+/* Allow for the two struct bidi_it objects too, since they can be big.
+ With MAX_ALLOCA of 16 KiB, this should allow at least 900 slots in the
BPA stack, which should be more than enough for actual bidi text. */
-#define MAX_BPA_STACK ((int)max (MAX_ALLOCA / sizeof (bpa_stack_entry), 1))
+enum { MAX_BPA_STACK = max (1, ((MAX_ALLOCA - 2 * sizeof (struct bidi_it))
+ / sizeof (bpa_stack_entry))) };
/* UAX#9 says to match opening brackets with the matching closing
brackets or their canonical equivalents. As of Unicode 8.0, there
#define PUSH_BPA_STACK \
do { \
int ch; \
- if (bpa_sp < MAX_BPA_STACK - 1) \
+ if (bpa_sp < MAX_BPA_STACK - 1 && bidi_cache_last_idx <= INT_MAX) \
{ \
bpa_sp++; \
ch = CANONICAL_EQU (bidi_it->ch); \
ptrdiff_t pairing_pos;
int idx_at_entry = bidi_cache_idx;
- eassert (MAX_BPA_STACK >= 100);
+ verify (MAX_BPA_STACK >= 100);
bidi_copy_it (&saved_it, bidi_it);
/* bidi_cache_iterator_state refuses to cache on backward scans,
and bidi_cache_fetch_state doesn't bring scan_dir from the