[U-Boot] [PATCH] lcd: align bmp header when uncopmressing image
Wolfgang Denk
wd at denx.de
Mon Jun 3 13:18:29 CEST 2013
Dear Piotr Wilczek,
In message <000701ce6025$173886c0$45a99440$%wilczek at 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
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"God is a comedian playing to an audience too afraid to laugh."
- Voltaire
More information about the U-Boot
mailing list