From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/1191 Path: news.gmane.org!not-for-mail From: orc Newsgroups: gmane.linux.lib.musl.general Subject: Re: Silly question about strncpy(), strlen() and related funcs Date: Tue, 19 Jun 2012 14:44:12 +0800 Message-ID: <20120619144412.6c028709@sibserver.ru> References: <20120619025409.4ec1ed49@sibserver.ru> <20120618203514.GW17860@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1340088386 2240 80.91.229.3 (19 Jun 2012 06:46:26 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 19 Jun 2012 06:46:26 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-1191-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jun 19 08:46:25 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1SgsCk-0003IV-Kf for gllmg-musl@plane.gmane.org; Tue, 19 Jun 2012 08:46:22 +0200 Original-Received: (qmail 4075 invoked by uid 550); 19 Jun 2012 06:46:22 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 4053 invoked from network); 19 Jun 2012 06:46:18 -0000 In-Reply-To: <20120618203514.GW17860@port70.net> X-Mailer: claws-mail Xref: news.gmane.org gmane.linux.lib.musl.general:1191 Archived-At: 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.