Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 19 Jun 2012 14:44:12 +0800
From: orc <>
Subject: Re: Silly question about strncpy(), strlen() and related

On Mon, 18 Jun 2012 22:35:14 +0200
Szabolcs Nagy <> wrote:

> * orc <> [2012-06-19 02:54:09 +0800]:
> > What ALIGN and additional checks like 'if (((uintptr_t)s & ALIGN) ==
> > ((uintptr_t)d & ALIGN))' {...} are mean in src/string/strpcpy.c and
> > similiar functions?
> i assume you meant stpncpy.c

Yes, my typo.

> it checks whether s(ource) and d(estination) pointers
> have the same alignment relative to word boundaries
> (uintptr_t)s makes the pointer available for integer arithmetics
> ALIGN is a bit mask 00..01..11 such that a word aligned pointer
> has 0 bits where ALIGN has 1s
> so the expression
>   (uintptr_t)s & ALIGN
> checks if s is word aligned
> (eg on 32bit systems a word aligned pointer is a multiple of 4
> so it should end with two 0s)
> (alignment matters because even though the granularity of
> addressing is 1byte, load/store of >1byte objects can
> only be done (efficiently) with certain alignment)

Thanks for explanation. I've already seen in debugger that it works with
pointers, but how it works with them was somewhat cryptic for me.
Rich's explanation below helped me to understand the rest of code.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.