Refactor validate_user_string to remove unnecessary variable to track length of str

This commit is contained in:
sBubshait
2024-11-13 18:30:24 +00:00
parent 9549ca28e5
commit 31ea215805

View File

@@ -446,13 +446,12 @@ validate_user_string (const char *str)
if (str == NULL || !is_user_vaddr (str)) if (str == NULL || !is_user_vaddr (str))
syscall_exit (EXIT_FAILURE); syscall_exit (EXIT_FAILURE);
size_t length = 0;
size_t offset = (uintptr_t) str % PGSIZE; size_t offset = (uintptr_t) str % PGSIZE;
/* We move page by page, checking if the page is mapped to physical memory. */ /* We move page by page, checking if the page is mapped to physical memory. */
for (;;) for (;;)
{ {
void *page = pg_round_down (str + length); void *page = pg_round_down (str);
if (!is_user_vaddr(page) || if (!is_user_vaddr(page) ||
pagedir_get_page (thread_current ()->pagedir, page) == NULL) pagedir_get_page (thread_current ()->pagedir, page) == NULL)