From 579b9ed3491aaddd8a8c1123ff1fae897cbb7b24 Mon Sep 17 00:00:00 2001 From: Starnakin Date: Fri, 18 Oct 2024 15:41:55 +0200 Subject: [PATCH] opti: memory: for loop stop iterate when not enough block is available --- src/memory/frame.c | 2 +- src/memory/page.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/memory/frame.c b/src/memory/frame.c index 1c0b4bf..ad256c2 100644 --- a/src/memory/frame.c +++ b/src/memory/frame.c @@ -14,7 +14,7 @@ static uint32_t remaining_frames = MAX_FRAMES; static int32_t find_next_block(size_t nb_frames) { - for (uint32_t i = 1; i < MAX_FRAMES; i++) { + for (uint32_t i = 1; i + nb_frames < MAX_FRAMES - 1; i++) { uint32_t j; for (j = 0; frame_table[i + j] == 0 && j < nb_frames; j++) ; diff --git a/src/memory/page.c b/src/memory/page.c index 947f894..4a78ee3 100644 --- a/src/memory/page.c +++ b/src/memory/page.c @@ -14,7 +14,7 @@ extern uint32_t page_table1[PT_SIZE]; static int16_t find_next_block(size_t nb_pages) { - for (uint16_t i = 1; i < PT_SIZE - 1; i++) { + for (uint16_t i = 1; i + nb_pages < PT_SIZE - 1; i++) { uint16_t j; for (j = 0; page_table1[i + j] >> 12 == i + j && j < nb_pages; j++)