From 09750b7388145961d8c457ca23dfcb8ca7914e3c Mon Sep 17 00:00:00 2001 From: Yi-Ting Shih Date: Mon, 6 Apr 2026 22:05:23 +0800 Subject: [PATCH] Fix: wtf is size <0 --- code/userprog/ksyscall.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/userprog/ksyscall.h b/code/userprog/ksyscall.h index 68718f1..afe38e8 100755 --- a/code/userprog/ksyscall.h +++ b/code/userprog/ksyscall.h @@ -53,6 +53,8 @@ OpenFileId SysOpen(char *name) { } int SysWrite(char *buffer, int size, OpenFileId id) { + if (size < 0) // Invalid size + return -1; if (id == 1) { // Console output (stdout) for (int i = 0; i < size; i++) kernel->synchConsoleOut->PutChar(buffer[i]); @@ -65,6 +67,8 @@ int SysWrite(char *buffer, int size, OpenFileId id) { } int SysRead(char *buffer, int size, OpenFileId id) { + if (size < 0) // Invalid size + return -1; if (id == 0) { // Console input (stdin) for (int i = 0; i < size; i++) buffer[i] = kernel->synchConsoleIn->GetChar();