From: Takashi Iwai Date: Thu, 18 Aug 2005 13:01:56 +0000 (+0000) Subject: Fix bitops to be 64bit clean X-Git-Tag: v1.0.10rc1~1 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=125498519dff7b2e578c44f0d0a08b50f5e90798;p=alsa-tools.git Fix bitops to be 64bit clean A patch from bug#1343: On all 64bit systems (the easiest example is amd64) ld10k1 crashes on use by lo10k1, some debugging tracked down the problem fairly quickly. 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. Zephaniah E. Hull. --- diff --git a/ld10k1/src/bitops.h b/ld10k1/src/bitops.h index 03f106f..f0b964e 100644 --- a/ld10k1/src/bitops.h +++ b/ld10k1/src/bitops.h @@ -15,13 +15,17 @@ * * C language equivalents written by Theodore Ts'o, 9/26/92 */ +/* + * Converted to be independent of the size of longs. + * Zephaniah E. Hull 2005-08-15. + */ __inline__ int set_bit(int nr, unsigned long * addr) { int mask, retval; - addr += nr >> 5; - mask = 1 << (nr & 0x1f); + addr += nr >> (sizeof(long) + 1); + mask = 1 << (nr & (sizeof(long) * 8 - 1)); retval = (mask & *addr) != 0; *addr |= mask; return retval; @@ -31,8 +35,8 @@ __inline__ int clear_bit(int nr, unsigned long * addr) { int mask, retval; - addr += nr >> 5; - mask = 1 << (nr & 0x1f); + addr += nr >> (sizeof(long) + 1); + mask = 1 << (nr & (sizeof(long) * 8 - 1)); retval = (mask & *addr) != 0; *addr &= ~mask; return retval; @@ -42,8 +46,8 @@ __inline__ int test_bit(int nr, unsigned long * addr) { int mask; - addr += nr >> 5; - mask = 1 << (nr & 0x1f); + addr += nr >> (sizeof(long) + 1); + mask = 1 << (nr & (sizeof(long) * 8 - 1)); return ((mask & *addr) != 0); }