diff --git a/inc/ft_malloc_internal.h b/inc/ft_malloc_internal.h index 5de9584..a5a42b7 100644 --- a/inc/ft_malloc_internal.h +++ b/inc/ft_malloc_internal.h @@ -6,7 +6,7 @@ /* By: gtertysh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/05/06 22:37:07 by foton #+# #+# */ -/* Updated: 2019/05/06 22:40:18 by gtertysh ### ########.fr */ +/* Updated: 2019/05/08 19:45:18 by gtertysh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -47,4 +47,4 @@ typedef struct s_arena extern t_arena g_base; -#endif \ No newline at end of file +#endif diff --git a/src/malloc.c b/src/malloc.c index 17babd1..95baa43 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -6,7 +6,7 @@ /* By: gtertysh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/05/06 22:35:57 by foton #+# #+# */ -/* Updated: 2019/05/07 22:06:49 by gtertysh ### ########.fr */ +/* Updated: 2019/05/08 19:44:07 by gtertysh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -96,10 +96,10 @@ void *malloc(size_t size) size = CHUNK_SIZE(size); arena = g_base.next; arena_type = get_arena_type(size); - while(!space) + while (!space) { - if(arena->type == arena_type && (heap = arena->heap)) - while(!space && heap) + if (arena->type == arena_type && (heap = arena->heap)) + while (!space && heap) { if (heap->size >= size && heap->is_free) space = chunk_heap(heap, size); @@ -111,4 +111,4 @@ void *malloc(size_t size) return (NULL); } return (space + 1); -} \ No newline at end of file +} diff --git a/src/realloc.c b/src/realloc.c index 5c5111a..6bd37d8 100644 --- a/src/realloc.c +++ b/src/realloc.c @@ -6,7 +6,7 @@ /* By: gtertysh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/05/06 22:35:48 by foton #+# #+# */ -/* Updated: 2019/05/07 00:25:13 by gtertysh ### ########.fr */ +/* Updated: 2019/05/08 19:44:41 by gtertysh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,4 +30,4 @@ void *realloc(void *ptr, size_t size) ft_memmove(new_chunk, ptr, chunk->size - CHUNK_SIZE(0)); free(ptr); return (new_chunk); -} \ No newline at end of file +} diff --git a/subprojects/libft/ft_putendl_fd.c b/subprojects/libft/ft_putendl_fd.c index 5eee2d4..91421e3 100644 --- a/subprojects/libft/ft_putendl_fd.c +++ b/subprojects/libft/ft_putendl_fd.c @@ -6,7 +6,7 @@ /* By: gtertysh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/04 15:17:18 by gtertysh #+# #+# */ -/* Updated: 2016/12/04 15:24:55 by gtertysh ### ########.fr */ +/* Updated: 2019/05/08 19:48:54 by gtertysh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,8 +16,8 @@ void ft_putendl_fd(char const *s, int fd) { if (s) while (*s) - if(write(fd, s++, 1) == -1) + if (write(fd, s++, 1) == -1) return ; - if(write(fd, "\n", 1) == -1) + if (write(fd, "\n", 1) == -1) return ; } diff --git a/t/malloc_tests.c b/t/malloc_tests.c index 9b504b9..97d4601 100644 --- a/t/malloc_tests.c +++ b/t/malloc_tests.c @@ -6,7 +6,7 @@ /* By: gtertysh +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/05/06 22:35:37 by foton #+# #+# */ -/* Updated: 2019/05/07 22:44:42 by gtertysh ### ########.fr */ +/* Updated: 2019/05/08 19:47:45 by gtertysh ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,10 +28,9 @@ int returns_not_null_pointer(void) g_base.next = &g_base; ptr = malloc(10); _IS(ptr != NULL); - ptr = ptr - 1; _IS(ptr->is_free == 0); - _IS(ptr->size == 10 + sizeof(t_chunk)); + _IS(ptr->size == 10 + sizeof(t_chunk)); _IS(ptr->magic == MAGIC); _IS(ptr->next == NULL); _IS(ptr->prev != NULL); @@ -48,25 +47,19 @@ int free_concatenates_adjacent_blocks(void) g_base.next = &g_base; ptr = malloc(10); next_malloc = malloc(10); - ptr -= 1; next_malloc -= 1; - free(ptr + 1); - _IS(ptr->is_free == 1); _IS(ptr->prev == next_malloc); _IS(next_malloc->is_free == 0); _IS(next_malloc->next == ptr); _IS(next_malloc->prev->prev == NULL); - heap = next_malloc->prev; free(next_malloc + 1); - _IS(heap->is_free == 1); _IS(heap->prev == NULL); _IS(heap->next == NULL); - _END("free_concatenates_adjacent_blocks"); } @@ -88,12 +81,9 @@ int malloc_creates_new_arena(void) second_arena_chunk = malloc(TINY); i++; } - _IS(g_base.next->next == &g_base); _IS(g_base.next->type == TINY); - second_arena_chunk = malloc(TINY); - _IS(g_base.next->next != &g_base); _IS(g_base.next->type == TINY); _IS(g_base.next->heap->next == second_arena_chunk - 1); @@ -108,7 +98,6 @@ int realloc_return_same_pointer(void) g_base.next = &g_base; ptr = malloc(20); new_ptr = realloc(ptr, 10); - _IS(ptr == new_ptr); _END("realloc_return_same_pointer"); } @@ -120,5 +109,5 @@ int main(void) _SHOULD(free_concatenates_adjacent_blocks); _SHOULD(malloc_creates_new_arena); _SHOULD(realloc_return_same_pointer); - return 0; -} \ No newline at end of file + return (0); +}