mirror of
https://github.com/alsa-project/alsa-tools.git
synced 2025-10-29 05:40:25 -04:00
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.
This commit is contained in:
parent
1d0881e212
commit
125498519d
1 changed files with 10 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue