#include <stdio.h>
#include <stdlib.h>
int main(void) {
long long int petabyte = 1024LL * 1024LL * 1024LL * 1024LL * 1024LL; // 10^15
printf("petabyte %lld \n", petabyte
);
volatile char *ptr
= (volatile char *)malloc(petabyte
); printf("malloc() - success, ptr = %p \n", ptr
);
ptr[petabyte - 1LL] = 10;
printf("ptr[petabyte - 1] = 10; - success \n");
printf("ptr[petabyte - 1] = %d \n", (int)(ptr
[petabyte
- 1LL
]));
free((void*)ptr
); // why the error is here? //printf("free() - success \n");
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBtYWluKHZvaWQpIHsKCQoJbG9uZyBsb25nIGludCBwZXRhYnl0ZSA9IDEwMjRMTCAqIDEwMjRMTCAqIDEwMjRMTCAqIDEwMjRMTCAqIDEwMjRMTDsJLy8gMTBeMTUKCXByaW50ZigicGV0YWJ5dGUgJWxsZCBcbiIsIHBldGFieXRlKTsKCQoJdm9sYXRpbGUgY2hhciAqcHRyID0gKHZvbGF0aWxlIGNoYXIgKiltYWxsb2MocGV0YWJ5dGUpOwoJcHJpbnRmKCJtYWxsb2MoKSAtIHN1Y2Nlc3MsIHB0ciA9ICVwIFxuIiwgcHRyKTsKCQoJcHRyW3BldGFieXRlIC0gMUxMXSA9IDEwOwoJcHJpbnRmKCJwdHJbcGV0YWJ5dGUgLSAxXSA9IDEwOyAtIHN1Y2Nlc3MgXG4iKTsKCQoJcHJpbnRmKCJwdHJbcGV0YWJ5dGUgLSAxXSA9ICVkIFxuIiwgKGludCkocHRyW3BldGFieXRlIC0gMUxMXSkpOwoJCglmcmVlKCh2b2lkKilwdHIpOwkvLyB3aHkgdGhlIGVycm9yIGlzIGhlcmU/CgkvL3ByaW50ZigiZnJlZSgpIC0gc3VjY2VzcyBcbiIpOwoJCglyZXR1cm4gMDsKfQo=