Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part 5: page_num out of bounds #102

Open
duncanchiu409 opened this issue Jul 28, 2023 · 1 comment
Open

Part 5: page_num out of bounds #102

duncanchiu409 opened this issue Jul 28, 2023 · 1 comment

Comments

@duncanchiu409
Copy link

duncanchiu409 commented Jul 28, 2023

If page_num start from 0 to TABLE_MAX_PAGE - 1, not 1, the if statement should be this instead. Tell me if I am right or wrong.

void* get_page(Pager* pager, uint32_t page_number){
    if(page_number >= TABLE_MAX_PAGES){
        printf("Tried to fetch page number out of bounds. %d > %d\n", page_number, TABLE_MAX_PAGES);
        exit(EXIT_FAILURE);
    }
@skypaver
Copy link

skypaver commented Aug 8, 2023

I noticed the same problem. I think you're right.

Maybe there's a similar problem also in the function get_page (line 248 in db.c):

void* get_page(Pager* pager, uint32_t page_number){
    ...
    if (page_num <= num_pages) {
        lseek(pager->file_descriptor, page_num * PAGE_SIZE, SEEK_SET);
        ...
    }
    ...
 }

(line 248 in db.c)if (page_num <= num_pages) I think it should be if (page_num < num_pages). Since the page_num is an index starts from 0 to TABLE_MAX_PAGE - 1, and the num_pages starts from 1.

I'm not quite sure. Could you please tell me if I am right or wrong? Thanks so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants