opflags: Convert is_class and is_reg_class to helpers

So we can test for out of bound access and make
helpers safe to use.

https://bugzilla.nasm.us/show_bug.cgi?id=3392447

Reported-by: Jun <jxx13@psu.edu>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov 2018-10-13 22:57:30 +03:00
parent 67f2ca2b3f
commit 3c755dac88

View file

@ -40,6 +40,7 @@
#include "compiler.h"
#include "tables.h" /* for opflags_t and nasm_reg_flags[] */
#include "regs.h"
/*
* Here we define the operand types. These are implemented as bit
@ -176,8 +177,17 @@
#define REG_CLASS_OPMASK GEN_REG_CLASS(8)
#define REG_CLASS_BND GEN_REG_CLASS(9)
#define is_class(class, op) (!((opflags_t)(class) & ~(opflags_t)(op)))
#define is_reg_class(class, reg) is_class((class), nasm_reg_flags[(reg)])
static inline bool is_class(opflags_t class, opflags_t op)
{
return !(class & ~op);
}
static inline bool is_reg_class(opflags_t class, opflags_t reg)
{
if (reg >= EXPR_REG_START && reg <= EXPR_REG_END)
return is_class(class, nasm_reg_flags[reg]);
return false;
}
#define IS_SREG(reg) is_reg_class(REG_SREG, (reg))
#define IS_FSGS(reg) is_reg_class(REG_FSGS, (reg))