Changeset 12932
- Timestamp:
- Sep 28, 2011, 4:07:35 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/bitfield.c
r12927 r12932 171 171 assert( b->bit_count > 0 ); 172 172 173 if( b->alloc_count ) 173 if( b->alloc_count ) { 174 assert( b->alloc_count <= n ); 174 175 memcpy( bits, b->bits, b->alloc_count ); 175 else if( tr_bitfieldHasAll( b ) )176 } else if( tr_bitfieldHasAll( b ) ) { 176 177 set_all_true( bits, b->bit_count ); 178 } 177 179 178 180 *byte_count = n; … … 181 183 182 184 static void 183 tr_bitfieldEnsureBitsAlloced( tr_bitfield * b, size_t n th)185 tr_bitfieldEnsureBitsAlloced( tr_bitfield * b, size_t n ) 184 186 { 185 187 size_t bytes_needed; … … 187 189 188 190 if( has_all ) 189 bytes_needed = get_bytes_needed( MAX( n th, b->true_count ) + 1);191 bytes_needed = get_bytes_needed( MAX( n, b->true_count ) ); 190 192 else 191 bytes_needed = get_bytes_needed( n th + 1);193 bytes_needed = get_bytes_needed( n ); 192 194 193 195 if( b->alloc_count < bytes_needed ) … … 200 202 set_all_true( b->bits, b->true_count ); 201 203 } 204 } 205 206 static void 207 tr_bitfieldEnsureNthBitAlloced( tr_bitfield * b, size_t nth ) 208 { 209 /* count is zero-based, so we need to allocate nth+1 bits before setting the nth */ 210 tr_bitfieldEnsureBitsAlloced( b, nth + 1 ); 202 211 } 203 212 … … 333 342 if( !tr_bitfieldHas( b, nth ) ) 334 343 { 335 tr_bitfieldEnsure BitsAlloced( b, nth );344 tr_bitfieldEnsureNthBitAlloced( b, nth ); 336 345 b->bits[nth >> 3u] |= ( 0x80 >> ( nth & 7u ) ); 337 346 tr_bitfieldIncTrueCount( b, 1 ); … … 359 368 em = 0xff << ( 7 - ( end & 7 ) ); 360 369 361 tr_bitfieldEnsure BitsAlloced( b, end );370 tr_bitfieldEnsureNthBitAlloced( b, end ); 362 371 if( sb == eb ) 363 372 { … … 382 391 if( !tr_bitfieldHas( b, nth ) ) 383 392 { 384 tr_bitfieldEnsure BitsAlloced( b, nth );393 tr_bitfieldEnsureNthBitAlloced( b, nth ); 385 394 b->bits[nth >> 3u] &= ( 0xff7f >> ( nth & 7u ) ); 386 395 tr_bitfieldIncTrueCount( b, -1 ); … … 409 418 em = ~( 0xff << ( 7 - ( end & 7 ) ) ); 410 419 411 tr_bitfieldEnsure BitsAlloced( b, end );420 tr_bitfieldEnsureNthBitAlloced( b, end ); 412 421 if( sb == eb ) 413 422 {
Note: See TracChangeset
for help on using the changeset viewer.