Skip to content

Commit 558004c

Browse files
fix align 8
1 parent 03e424c commit 558004c

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

0x08-malloc/EYNTK/7-naive_malloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <unistd.h>
22

33
#define PAGE_SIZE ((size_t) sysconf(_SC_PAGESIZE))
4-
#define align8(x) (((((x) - 1) >> 2) << 2 )+ 8)
4+
#define align8(x) (x % 8) ? (x + (8 - x % 8)) : x
55

66
static void *heap_start;
77

0x08-malloc/malloc.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,19 @@
55
#include <stdio.h>
66

77
#define PAGE_SIZE ((size_t) sysconf(_SC_PAGESIZE))
8-
#define align8(x) (((((x) - 1) >> 2) << 2) + 8)
8+
#define align8(x) ((x % 8) ? (x + (8 - x % 8)) : x)
99

1010
typedef struct s_block *t_block;
1111

1212
/**
1313
* struct s_block - Holds the details of each block
1414
* @size: size of block
1515
* @next: pointer to next block
16-
* @free: 1 if block is free else 0
17-
* @data: data stored at the block
1816
*/
1917
struct s_block
2018
{
2119
size_t size;
22-
t_block next;
23-
int free;
24-
char data[1];
20+
struct s_block *next;
2521
};
2622

2723
#define BLOCK_SIZE sizeof(struct s_block)

0 commit comments

Comments
 (0)