From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/1118 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: FreeSec crypt() Date: Wed, 13 Jun 2012 13:36:31 -0400 Message-ID: <20120613173631.GG163@brightrain.aerifal.cx> References: <20120612235113.GA21296@openwall.com> <20120613011842.GA163@brightrain.aerifal.cx> <20120613061032.GH17860@port70.net> <20120613125839.GB163@brightrain.aerifal.cx> <20120613131807.GA22380@openwall.com> <20120613145603.GD163@brightrain.aerifal.cx> <20120613164546.GA23407@openwall.com> <20120613173248.GK17860@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 X-Trace: dough.gmane.org 1339609260 22141 80.91.229.3 (13 Jun 2012 17:41:00 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 13 Jun 2012 17:41:00 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-1119-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jun 13 19:40:59 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from [195.42.179.200] (helo=mother.openwall.net) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1SerYw-0005rZ-K9 for gllmg-musl@plane.gmane.org; Wed, 13 Jun 2012 19:40:58 +0200 Original-Received: (qmail 16342 invoked by uid 550); 13 Jun 2012 17:40:58 -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 16334 invoked from network); 13 Jun 2012 17:40:58 -0000 Content-Disposition: inline In-Reply-To: <20120613173248.GK17860@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-Broken-Reverse-DNS: no host name found for IP address 195.42.179.200 Xref: news.gmane.org gmane.linux.lib.musl.general:1118 Archived-At: On Wed, Jun 13, 2012 at 07:32:48PM +0200, Szabolcs Nagy wrote: > * Solar Designer [2012-06-13 20:45:46 +0400]: > > On Wed, Jun 13, 2012 at 10:56:03AM -0400, Rich Felker wrote: > > > Well if char is signed, (char)0x80 << 1 is -256. If char is unsigned, > > > (char)0x80 << 1 is 256. > > > > Sure, but we had: > > > > const char *key; > > u_char *q; > > *q++ = *key << 1; > > > > so while *key << 1 is either -256 or 256 (promoted to int or unsigned > > int), those high bits get dropped on the assignment to *q anyway, > > resulting in the same value there either way. No? > > yes the code happens to work whenever -128<<1 is -256 > > and i assume -256 is what most compilers will give > usually in case of two's complement int representation > > but -128<<1 is UB and should be fixed anyway Note that x<<1 is always equal to x*2 when both are defined, and the latter is defined in our case since the range of x is much smaller than half the range of int. So if the underlying pointer type issue isn't fixed, just changing <<1 to *2 would work. In general, portable code wanting to use x<