Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 18 Jun 2012 22:35:14 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: Re: Silly question about strncpy(), strlen() and related funcs

* orc <orc@...server.ru> [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

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)

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.