]> www.infradead.org Git - users/sagi/nvme-cli.git/commit
Don't cast pointers, cast values.
authorWalter Doekes <wjdoekes@osso.nl>
Wed, 16 Dec 2015 14:08:11 +0000 (15:08 +0100)
committerWalter Doekes <wjdoekes@osso.nl>
Wed, 16 Dec 2015 14:24:06 +0000 (15:24 +0100)
commit97ff45ce711e1f356641d25f898f9b53fbb79634
treee6fe63f4ee97ab22bc57311cbb816db82b735c13
parent690d8d62828f20649d698b50c298964a9a3be85a
Don't cast pointers, cast values.

The compiler rightly warned about an issue in ed3848130, but the fix was
wrong.

There is no guarantee that an int is exactly 32 bits and no guarantee
that a long long is exactly 64 bits. The former one is guaranteed to be
at least 16 bits (but we can safely assume 32 for non-ancient machines).

Imagine an u32 array:

    0... 1... 2... 3... 4... 5...

Now cast the pointer to the zeroth element to a 64-bits-int-pointer;
64bit sized int are quite common.

    0.......  1.......  2.......

Writing to 0, 1 and 2 would put values in 0, 2 and 4 (on little endian).
And if there is enough data, it would overwrite the stack.

This change moves the casting to the point where the individual values
are copied. That's safe.
nvme.c