MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / libc_mem

Function libc_mem

examples/libc/memory.c:23–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23int libc_mem(void)
24{
25 void *p;
26 int save;
27
28 errno = 0;
29
30 p = malloc(-1);
31 save = errno;
32
33 if (p != NULL)
34 merror("malloc (-1) succeeded.");
35
36 if (p == NULL && save != ENOMEM)
37 merror("errno is not set correctly");
38
39 p = malloc(10);
40 if (p == NULL)
41 merror("malloc (10) failed.");
42
43 /* realloc (p, 0) == free (p). */
44 p = realloc(p, 0);
45 if (p != NULL)
46 merror("realloc (p, 0) failed.");
47
48 p = malloc(0);
49 if (p == NULL)
50 {
51 printf("malloc(0) returns NULL\n");
52 }
53
54 p = realloc(p, 0);
55 if (p != NULL)
56 merror("realloc (p, 0) failed.");
57
58 return errors != 0;
59}
60FINSH_FUNCTION_EXPORT(libc_mem, memory test for libc);

Callers

nothing calls this directly

Calls 4

merrorFunction · 0.85
mallocFunction · 0.50
reallocFunction · 0.50
printfFunction · 0.50

Tested by

no test coverage detected