-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest5.c
40 lines (36 loc) · 783 Bytes
/
test5.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include "inc/malloc.h"
void print(char *s)
{
write(1, s, strlen(s));
}
int main()
{
int i;
int alignment;
char *addr;
i = 1;
alignment = 2 * sizeof(size_t);
// printf("%d\n",alignment);
while (i <= 100)
{
addr = (char*)malloc(i);
// show_alloc_mem();
if (addr == NULL)
{
print("Failed to allocate memory\n");
exit(1);
}
if ((((unsigned long) (addr)) % alignment) != 0)
{
printf("pb: %lu\n",(unsigned long) (addr) % alignment);
print("malloc returned a non aligned boundary\n");
exit(1);
}
i++;
free(addr);
}
}