Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ccccff
size_t size = 16;
size_t alignment = 1<<12;
float *ptr;
double *ptr1;

ptr = aligned_alloc(align , size);

if(align == alignof(ptr1)) {
ptr1 = realloc(ptr, size);
}

Implementation details

This program produces the following (unexpected) output on the x86_64-redhat-linux platform that was compiled with gcc version 4.1.2.
(ptr0 is initialized to 12.5 and ptr1 is initialized to 25.5)

ptr0 (0x2b7000000000) = 12.500000
ptr1 (0x2b7000000004) = 25.500000
ptr10 (0x2b7000000000) = 12.500000
ptr11 (0x2b7000000008) = 0.000000

Risk Assessment

Improper alignment could lead to accessing arbitrary memory locations and write into it.

...