Update validate_user_pointer to perform no memory checks when size is 0

This commit is contained in:
sBubshait
2024-11-04 00:38:58 +00:00
parent e718159ed8
commit 3a258cf064

View File

@@ -80,11 +80,15 @@ exit (int status UNUSED)
}
/* Validates if a block of memory starting at PTR and of size SIZE bytes is
fully contained within user virtual memory. */
fully contained within user virtual memory. Kills the thread (by calling
thread_exit) if the memory is invalid. Otherwise, returns the PTR given.
If the size is 0, the function does no checks and returns PTR.*/
static void *
validate_user_pointer (void *ptr, size_t size)
{
if (ptr == NULL || !is_user_vaddr (ptr) || !is_user_vaddr (ptr + size - 1))
if (size > 0 && (ptr == NULL ||
!is_user_vaddr (ptr) ||
!is_user_vaddr (ptr + size - 1)))
thread_exit ();
return ptr;