From cbc9aef2953df0245c39ff5894170566ff2a396e Mon Sep 17 00:00:00 2001 From: Alex <alexander3.stratford@live.uwe.ac.uk> Date: Thu, 5 Dec 2019 10:20:27 +0000 Subject: [PATCH] Added guard condition to seek Fixed guard condition in filesize to exit properly --- userprog/syscall_filesize.c | 1 + userprog/syscall_seek.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/userprog/syscall_filesize.c b/userprog/syscall_filesize.c index aff7fe7..7247c5c 100644 --- a/userprog/syscall_filesize.c +++ b/userprog/syscall_filesize.c @@ -13,6 +13,7 @@ void syscall_filesize(struct intr_frame *f) { struct file *file = get_associated_file_pointer(file_descriptor); if (file == NULL) { // Checking if file is empty or non-existent f->eax -1; // Returning failure state + return; } // Using the file_length function in file.h to get the length and store it int size = file_length(file); diff --git a/userprog/syscall_seek.c b/userprog/syscall_seek.c index 9a665a1..e016d6f 100644 --- a/userprog/syscall_seek.c +++ b/userprog/syscall_seek.c @@ -17,6 +17,9 @@ void syscall_seek(struct intr_frame *f) { // pop off second int argument from interrupt frame unsigned file_pos = *((unsigned*)((int*)f->esp + 2)); struct file *file = get_associated_file_pointer(file_descriptor); + if (file == NULL) { // Checking if file is empty or non-existent + return; + } // Seek through the file file_seek(file, file_pos); } -- GitLab