Print allocated memory
This commit is contained in:
parent
42bd431dca
commit
c39c0c22ac
|
@ -1,3 +1,4 @@
|
||||||
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -8,6 +9,7 @@ int main(void) {
|
||||||
|
|
||||||
while (s) {
|
while (s) {
|
||||||
void *p;
|
void *p;
|
||||||
|
errno = 0;
|
||||||
if (p = malloc(s)) {
|
if (p = malloc(s)) {
|
||||||
sum += s;
|
sum += s;
|
||||||
printf("%lu - %lu\n",
|
printf("%lu - %lu\n",
|
||||||
|
@ -17,6 +19,11 @@ int main(void) {
|
||||||
memset(p, 'a', s);
|
memset(p, 'a', s);
|
||||||
s *= 2;
|
s *= 2;
|
||||||
} else {
|
} else {
|
||||||
|
printf("%lu - %lu: %s\n",
|
||||||
|
(unsigned long)s,
|
||||||
|
(unsigned long)sum,
|
||||||
|
strerror(errno)
|
||||||
|
);
|
||||||
s /= 2;
|
s /= 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue