Fix undefined behavior of stack_{push,set}

This makes sure that stack_ptr is evaluated / updated
after the evaluation of the macro argument.
This commit is contained in:
kichikuou
2019-11-01 19:48:37 +09:00
parent 470c051124
commit e6a3bf4c06
+12 -2
View File
@@ -91,9 +91,19 @@ static inline union vm_value vm_float(float v)
bool: vm_bool, \
float: vm_float)(v)
static inline void stack_set_value(int n, union vm_value v)
{
stack[stack_ptr - (1 + n)] = v;
}
static inline void stack_push_value(union vm_value v)
{
stack[stack_ptr++] = v;
}
// Set the Nth value from the top of the stack to V.
#define stack_set(n, v) (stack[stack_ptr - (1 + (n))] = vm_value_cast(v))
#define stack_push(v) (stack[stack_ptr++] = vm_value_cast(v))
#define stack_set(n, v) (stack_set_value((n), vm_value_cast(v)))
#define stack_push(v) (stack_push_value(vm_value_cast(v)))
union vm_value stack_pop(void);
int vm_string_ref(struct string *s);