[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scrypt's malloc() alignment



On Fri, Nov 16, 2012 at 02:17:15AM -0800, Colin Percival wrote:
> I was using uintptr_t because I figured it's safer than casting to a size_t
> which might or might not be the same size, and I'm not aware of any system
> where uintptr_t doesn't exist but other POSIX functionality does.
> 
> So I don't think there's anything much to be gained from changing this, and
> possibly something to be lost.

Yeah, it's not much.  Still I think staying within pointer arithmetic
only, without converting to ints and back, is a safer bet.

Besides malloc() alignment, there are also uses like:

	uint32_t * X = (void *)((uintptr_t)(B) + (2 * r - 1) * 64);

I think these would better written like:

	uint32_t * X = (void *)((uint8_t *)B + (2 * r - 1) * 64);

or maybe:

	uint32_t * X = (uint32_t *)((uint8_t *)B + (2 * r - 1) * 64);

Alexander