Description
Alignment code defined in ink_align.h is:
pointer = (char *)(((unsigned long) pointer + widthmask) & (~widthmask));
It is assumed that widthmask parameter is power of two minus one.
The upper math gives wrong results.
Eg.
Aligning memory with the base address of 0x1001 to 512 bytes is done as following in the code:
aligned = align_pointer_forward(base, 511);
This gives resulting address: 0x1200 which is fine
However if the base address was 0x11F0 the resulting address would be 0x1F0 instead 0x1200
Solution is to use the
pointer = (char *)(((unsigned long) pointer + alignment) & ~(alignment - 1));
and use the real alignment numbers in the api instead masked values