]> git.alsa-project.org Git - alsa-tools.git/commitdiff
Fix bitops to be 64bit clean
authorTakashi Iwai <tiwai@suse.de>
Thu, 18 Aug 2005 13:01:56 +0000 (13:01 +0000)
committerTakashi Iwai <tiwai@suse.de>
Thu, 18 Aug 2005 13:01:56 +0000 (13:01 +0000)
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.

ld10k1/src/bitops.h

index 03f106f2e16ffda3792329567ef14aa370389c5e..f0b964ef3dbcdd9a31ac6d705f3a210dd679baa6 100644 (file)
  * 
  * 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);
 }