...
Code Block |
---|
#include <stdlib.h> #include <stdio.h> int main(void) { size_t size = 8; size_t re-size = 101024; size_t align = 1 << 12; float *ptr; double *ptr1; if(posix_memalign((void **)&ptr, align , 8size) != 0) { exit(0); } ptr[0] = 12.5; ptr[1] = 25.5; printf("memory aligned to %d bytes\n\n",align); printf("ptr[0] : %p = %f\n",ptr, ptr[0]); printf("ptr[1] : %p = %f\n\n",&ptr[1], ptr[1]); if((ptr1 = realloc((int *)ptr, 1024re-size)) == NULL) { exit(0); } printf("After realloc(): \n"); printf("ptr1[0] : %p = %lf\n",ptr1, ptr[0]); printf("ptr1[1] : %p = %lf\n\n",&ptr1[1], ptr1[1]); free(ptr1); return 0; } |
...
Code Block |
---|
memory aligned to 4096 bytes ptr[0] : 0xb43c0000x39bf000 = 12.500000 ptr[1] : 0xb43c0040x39bf004 = 25.500000 After realloc(): ptr1[0] : 0xb43c0000x39be010 = 120.500000000000 ptr1[1] : 0xb43c0080x39be018 = 0.000000 |
Risk Assessment
...