From: Takashi Iwai Subject: Re: [ALSA - tools 0001343]: bitops not 64bit clean Date: Tue, 08 Nov 2005 18:14:02 +0100 Message-ID: References: Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: Sender: alsa-devel-admin@lists.sourceforge.net Errors-To: alsa-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: "D. Hugh Redelmeier" Cc: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org At Sun, 6 Nov 2005 17:56:30 -0500 (EST), D. Hugh Redelmeier wrote: > > | From: bugtrack@alsa-project.org > | Date: Fri, 26 Aug 2005 14:42:44 +0200 > > | The following issue has been RESOLVED. > | ====================================================================== > | > | ====================================================================== > > | The bitops functions (set_bit and associated) that ld10k1 use come from > | the linux kernel, and assume that longs are 32bit only, causing a buffer > | overflow of the bit buffer. > | > | The attached patch fixes the bitops to be independent of the size of > | longs, and is confirmed to fix the bug on my box. > > | diff -ur alsa-tools-1.0.9/ld10k1/src/bitops.h > | alsa-tools-1.0.9.mine/ld10k1/src/bitops.h > | --- alsa-tools-1.0.9/ld10k1/src/bitops.h 2005-03-18 08:41:02.000000000 > > | - addr += nr >> 5; > | - mask = 1 << (nr & 0x1f); > | + addr += nr >> (sizeof(long) + 1); > | + mask = 1 << (nr & (sizeof(long) * 8 - 1)); > > [A similar change appears two other places in the bitops.h.] > > You cans see this in CVS: > http://cvs.sourceforge.net/viewcvs.py/alsa/alsa-tools/ld10k1/src/bitops.h?rev=1.2&view=log > > This patch looks very wrong to me. The original code used 5 because > it is the base 2 log of the number of bits in an unsigned long > (thought to be always 32) and 0x1f because it is a mask with the > length of that same 5. > > When sizeof(unsigned long) == 4: > sizeof(long) + 1 == 5 > and > log2(sizeof(unsigned long) * 8) == 5 > so the new code should work in this case. > > When sizeof(unsigned long) == 8 > sizeof(long) + 1 == 9 > and > log2(sizeof(unsigned long) * 8) == 6 > so the new code should not work in this case. Yep, right. Fixed on CVS now. Takashi ------------------------------------------------------- SF.Net email is sponsored by: Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php