Skip to content

Commit

Permalink
Added case for NULL instructions
Browse files Browse the repository at this point in the history
This pull has addded a "edge case" for the `INSTR_NULL` cases that may
be passed into the `instr_get_tab` funciton. Further testing has found
that this function may be problematic and force segmentation faults
when faced with a `NULL` value in either the operands or `instr`
member. Now, this function will intentionally skip any `NULL` or `INST-
R_NULL` values.
  • Loading branch information
cheng-alvin committed Jan 4, 2025
1 parent 28bdd93 commit ea3a72a
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions libjas/instruction.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ instr_encode_table_t *instr_table[] =
#define CURR_TABLE instr_table[instr.instr][j]

instr_encode_table_t instr_get_tab(instruction_t instr) {
if (instr.instr == NULL && instr.operands == NULL) return INSTR_TERMINATOR;
if (IS_LABEL(instr)) return INSTR_TERMINATOR; // aka empty
const enum operands operand_list[4] = {
instr.operands[0].type, instr.operands[1].type,
Expand Down

0 comments on commit ea3a72a

Please sign in to comment.