From ea3a72ac7141ed7f64755b4241c140104ce42a8a Mon Sep 17 00:00:00 2001 From: Alvin Cheng Date: Sat, 4 Jan 2025 14:19:01 +1100 Subject: [PATCH] Added case for `NULL` instructions 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. --- libjas/instruction.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libjas/instruction.c b/libjas/instruction.c index a6c84e5..770a02b 100644 --- a/libjas/instruction.c +++ b/libjas/instruction.c @@ -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,