
Dear Piotr Wilczek,
In message 000701ce6025$173886c0$45a99440$%wilczek@samsung.com you wrote:
- /* align to 32-bit-aligned-address + 2 */
- if ((unsigned int)bmp % 0x04 != 0x02)
bmp = (bmp_image_t *)(((unsigned int)dst + 0x02) & ~0x01);
This is wrong. Suppose that bmp % 4 == 3, then (dst + 2) % 4 == 1, and thus ((dst + 2) & ~1) % 4 == 0, which is not an aligned+2 address.
You are right but here I'm aligning a pointer returned by malloc which is guaranteed to be aligned to 8 bytes. In fact it is sufficient only to add two bytes.
Such assumptions are black magic at best.
Please always consider the mentalk welfare of your follow programmers who for example might change this into a character array (say, a buffer on the stack) and suddenly experience mysetrious crashes.
Please always write code such that it is NOT based on non-obvious requirements.
Anyway, to make the code universal I provide a better alignment method.
Thanks.
Best regards,
Wolfgang Denk