diff --git a/include/mapnik/text/scrptrun.hpp b/include/mapnik/text/scrptrun.hpp index c219a2a0d..7cee74197 100644 --- a/include/mapnik/text/scrptrun.hpp +++ b/include/mapnik/text/scrptrun.hpp @@ -24,6 +24,9 @@ #include #pragma GCC diagnostic pop +const unsigned int STACK_SIZE = 1 << 7; // 2^n +const unsigned int STACK_MASK = STACK_SIZE - 1; + struct ScriptRecord { UChar32 startChar = 0; @@ -85,7 +88,7 @@ private: int32_t scriptEnd; UScriptCode scriptCode; - ParenStackEntry parenStack[128]; + ParenStackEntry parenStack[STACK_SIZE]; int32_t parenSP; static int8_t highBit(int32_t value); diff --git a/src/text/scrptrun.cpp b/src/text/scrptrun.cpp index bc16cb811..c2985397d 100644 --- a/src/text/scrptrun.cpp +++ b/src/text/scrptrun.cpp @@ -161,7 +161,7 @@ UBool ScriptRun::next() // characters above it on the stack will be poped. if (pairIndex >= 0) { if ((pairIndex & 1) == 0) { - parenSP = (++parenSP) % ARRAY_SIZE(parenStack); // avoid out-of-bounds access + parenSP = (++parenSP) & STACK_MASK; // avoid out-of-bounds access parenStack[parenSP].pairIndex = pairIndex; parenStack[parenSP].scriptCode = scriptCode; } else if (parenSP >= 0) {