Skip to content

Commit

Permalink
Fix bugued when fill entire block, need to add block size to computed…
Browse files Browse the repository at this point in the history
… block header offset
  • Loading branch information
Ycaro02 committed Apr 3, 2024
1 parent b87fe6f commit 0e74b94
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/show_alloc_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ static size_t print_bloc(t_page *data, int16_t hex_flag)
int total = 0;
t_block *block;

// size_t block_size = data->type & TINY ? TINY_SIZE : SMALL_SIZE;;
// block_size -= BLOCK_SIZE;

display_type(data->type);
ft_printf_fd(1, " : %p\n", data);
block = data->block;
Expand All @@ -53,6 +56,8 @@ static size_t print_bloc(t_page *data, int16_t hex_flag)
} else {
ft_printf_fd(1, "%p - %p", ptr, ptr + block->size);
ft_printf_fd(1, ": %U bytes\n", ptr + block->size - ptr);
ft_printf_fd(1, "block metadata size-> %u next-> %p\n", block->size, block->next);
ft_printf_fd(1, "block data-> |%s|\n", (char *)ptr);
}
total += ptr + block->size - ptr;
block = block->next;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ size_t get_align_by_type(e_type type)

if (!(type & LARGE))
type & TINY ? (align = TINY_SIZE) : (align = SMALL_SIZE);
return (align);
return (align + BLOCK_SIZE);
}

/** @brief get number of block in lst */
Expand Down
9 changes: 0 additions & 9 deletions test.c

This file was deleted.

32 changes: 30 additions & 2 deletions tester/src/test_implementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ void print(char *s) { write(1, s, strlen(s)); }
void prints(char *s1, char *s2, char *s3, char*s4) {
write(1, s1, strlen(s1));
write(1, s2, strlen(s2));
write(1, s3, strlen(s3));
write(1, s4, strlen(s4));
if (s3){
write(1, s3, strlen(s3));
}
if (s4) {
write(1, s4, strlen(s4));
}
write(1, "\n", 1);
}

Expand Down Expand Up @@ -141,12 +145,36 @@ int test4(char *version)
#endif
}


static void fill_full_tiny_page()
{
char *addr;
int i = 0;

int j = 0;

while (i < 100)
{
addr = (char*)malloc(128);
for (int j = 0; j < 128; j++) {
addr[j] = 'A';
}
addr[127] = '\0';
i++;
}
# ifdef USE_LIBFT_MALLOC /* define at compilation time */
show_alloc_mem();
#endif
}

int main(int argc, char **argv)
{
int test_flag = 0;
if (argc == 2) {
test_flag = atoi(argv[1]);
}
fill_full_tiny_page();

if (test_flag & TEST0)
test0(TEST_VERSION_NAME);
if (test_flag & TEST1)
Expand Down

0 comments on commit 0e74b94

Please sign in to comment.