TRAP ("stack underflow"); \
}
+#define CHECK_STACK_AVAILABLE(n) \
+ { \
+ char *stack_end; \
+ \
+ stack_end \
+ = (char *) interpreter->twilight_x; \
+ if (((char *) (interpreter->SP + (n)) \
+ > stack_end)) \
+ TRAP ("stack overflow"); \
+ }
+
#define CHECK_PREP() \
if (!is_prep) \
TRAP ("instruction executed not valid" \
? (TRAP ("stack underflow"), 0) \
: *(interpreter->SP - 1))
-#ifndef TEST
+#if !defined TEST || !0
#define PUSH(value) \
{ \
interpreter->SP++; \
}
-#else
+#else /* TEST && 0 */
#define PUSH(value) \
{ \
#define PUSH_UNCHECKED(value) PUSH (value)
-#endif
+#endif /* TEST && 0 */
-#define PUSH2(high, low) \
+#define PUSH2_UNCHECKED(high, low) \
{ \
- PUSH ((int16_t) ((int8_t) high) << 8 \
- | low); \
+ int16_t word; \
+ \
+ word = (((int8_t) high) << 8 | low); \
+ PUSH_UNCHECKED (word); \
} \
#define SRP0() \
#define NPUSHB() \
{ \
int b, nbytes, IP; \
+ unsigned char *ip; \
\
if ((IP = interpreter->IP + 1) \
>= interpreter->num_instructions) \
> interpreter->num_instructions) \
TRAP ("args to NPUSHB lie outside IS"); \
\
+ CHECK_STACK_AVAILABLE (nbytes); \
+ ip = interpreter->instructions; \
for (b = IP + 1; b < IP + 1 + nbytes; ++b) \
- PUSH (interpreter->instructions[b]); \
+ PUSH_UNCHECKED (ip[b]); \
\
interpreter->IP += nbytes + 1; \
}
#define NPUSHW() \
{ \
int b, nbytes, IP; \
+ unsigned char *ip; \
\
if ((IP = interpreter->IP + 1) \
>= interpreter->num_instructions) \
> interpreter->num_instructions) \
TRAP ("args to NPUSHW lie outside IS"); \
\
+ CHECK_STACK_AVAILABLE (nbytes / 2); \
+ ip = interpreter->instructions; \
for (b = IP + 1; b < IP + 1 + nbytes; \
b += 2) \
- PUSH2 (interpreter->instructions[b], \
- interpreter->instructions[b + 1]); \
+ PUSH2_UNCHECKED (ip[b], ip[b + 1]); \
\
interpreter->IP += nbytes + 1; \
}
#define PUSHB() \
{ \
int b, nbytes, IP; \
+ unsigned char *ip; \
\
IP = interpreter->IP; \
nbytes = opcode - 0xb0 + 1; \
> interpreter->num_instructions) \
TRAP ("args to PUSHB lie outside IS"); \
\
+ CHECK_STACK_AVAILABLE (nbytes); \
+ ip = interpreter->instructions; \
for (b = IP + 1; b < IP + nbytes + 1; ++b) \
- PUSH (interpreter->instructions[b]); \
+ PUSH_UNCHECKED (ip[b]); \
\
interpreter->IP += nbytes; \
}
#define PUSHW() \
{ \
int b, nbytes, IP; \
+ unsigned char *ip; \
\
IP = interpreter->IP; \
nbytes = (opcode - 0xb8 + 1) * 2; \
> interpreter->num_instructions) \
TRAP ("args to PUSHW lie outside IS"); \
\
+ CHECK_STACK_AVAILABLE (nbytes / 2); \
+ ip = interpreter->instructions; \
for (b = IP + 1; b < IP + nbytes + 1; \
b += 2) \
- PUSH2 (interpreter->instructions[b], \
- interpreter->instructions[b + 1]); \
+ PUSH2_UNCHECKED (ip[b], ip[b + 1]); \
\
interpreter->IP += nbytes; \
}
static struct sfnt_generic_test_args stack_overflow_test_args =
{
- (uint32_t[100]) { },
- 100,
+ (uint32_t[]) { },
+ 0,
true,
0,
};