From f25586a49bca3b0f9eb3af0fba55824038b94cdf Mon Sep 17 00:00:00 2001
From: Alex Stratford <alexander3.stratford@live.uwe.ac.uk>
Date: Wed, 4 Dec 2019 13:28:18 +0000
Subject: [PATCH] Added guard state for associating a file

---
 userprog/syscall_open.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/userprog/syscall_open.c b/userprog/syscall_open.c
index fadce95..fcbbe06 100644
--- a/userprog/syscall_open.c
+++ b/userprog/syscall_open.c
@@ -23,5 +23,10 @@ void syscall_open(struct intr_frame *f) {
 	}
 	// Described in system_calls.h, get a new file descriptor
 	int file_descriptor = associate_new_file_descriptor(file);
+
+	if (file_descriptor == -1) {
+		f->eax = -1; // Returning a failure state
+		return;
+	}
 	f->eax = file_descriptor; // Returning the file descriptor
 }
-- 
GitLab