diff options
author | Cyrill Gorcunov <gorcunov@gmail.com> | 2018-10-13 22:57:30 +0300 |
---|---|---|
committer | Cyrill Gorcunov <gorcunov@gmail.com> | 2018-10-13 22:57:30 +0300 |
commit | 3c755dac88039b718d52ef56e8f74b5f65f3b55b (patch) | |
tree | 410031506c17e0623316fbe958e338e3f12e958d | |
parent | 67f2ca2b3fb4e009ef3f7885e848b99e6a81ab29 (diff) | |
download | nasm-3c755dac88039b718d52ef56e8f74b5f65f3b55b.tar.gz |
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>
-rw-r--r-- | include/opflags.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/include/opflags.h b/include/opflags.h index 8311dcf6..28bb236f 100644 --- a/include/opflags.h +++ b/include/opflags.h @@ -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)) |