From 93acd46e25feb36f578e351c44e52e4aed21a1ec Mon Sep 17 00:00:00 2001 From: Powerbyte7 <40431794+Powerbyte7@users.noreply.github.com> Date: Tue, 17 Dec 2024 20:29:53 +0100 Subject: [PATCH] Fix segfault when using ANY If port is null, the program attempts to read at an illegal address with port->ip. This check prevents a segfault from occurring. --- src/node.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/node.c b/src/node.c index 8694605..fcd93fc 100644 --- a/src/node.c +++ b/src/node.c @@ -224,9 +224,11 @@ static inline Node *node_get_output_port(Node *n, int direction) LocationDirection dirs[] = {UP,LEFT,RIGHT,DOWN}; for(int i=0; i < 4; i++) { Node *port = n->ports[dirs[i]]; - Instruction *inst = &port->instructions[port->ip]; - if (port && inst->operation == MOV && inst->src_type == ADDRESS && (inst->src.direction == ANY || port->ports[inst->src.direction] == n) ) { - return port; + if (port) { + Instruction *inst = &port->instructions[port->ip]; + if (inst->operation == MOV && inst->src_type == ADDRESS && (inst->src.direction == ANY || port->ports[inst->src.direction] == n) ) { + return port; + } } } return NULL;