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

Wiki Markup
This program produces the following (unexpected) output on the x86_64-redhat-linux platform that was compiled with gcc version 4.1.2.


(ptr\[0\] is initialized to 12.5 and ptr\[1\] is initialized to 25.5)

Wiki Markup
ptr\[0\] (0x2b7000000000) = 12.500000


ptr\[1\] (0x2b7000000004) = 25.500000


ptr1\[0\] (0x2b7000000000) = 12.500000


ptr1\[1\] (0x2b7000000008) = 0.000000

Risk Assessment

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

...