Implemented malloc, abort, exit
This commit is contained in:
28
tests/memory.c
Normal file
28
tests/memory.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char buf[] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
|
||||
};
|
||||
|
||||
char *buf2 = malloc(sizeof(buf));
|
||||
memcpy(buf2, buf, sizeof(buf));
|
||||
|
||||
for (size_t i = 0; i < sizeof(buf2); i++) {
|
||||
if (buf[i] != buf2[i]) {
|
||||
printf("buf[%zu] != buf2[%zu] !!\n", i, i);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("copy ok.\n");
|
||||
free(buf2);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user