• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why does Swift crash my CFBitVector ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why does Swift crash my CFBitVector ?


  • Subject: Re: Why does Swift crash my CFBitVector ?
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Tue, 08 Jul 2014 09:31:25 +0700

On 8 Jul 2014, at 00:06, Clark S. Cox III <email@hidden> wrote:

>
>> On Jul 6, 2014, at 02:14, Gerriet M. Denkmann <email@hidden> wrote:
>>
>> class CrashVector
>> {
>> 	let lengthInBits : CFIndex 	= 133 	//	must be > 128
>> 	let badIndex : CFIndex 		= 129	//	128 ≤ badIndex < lengthInBits
>>
>> 	func makeCrash()
>> 	{
>> 		let bitVector = CFBitVectorCreateMutable( kCFAllocatorDefault, lengthInBits )
>> 		let bitCount = CFBitVectorGetCount( bitVector )
>> 		println("got BitVector with \(bitCount) bits")	//	why does it say 0 instead of 133 ?
>
> Because you’ve just set the *capacity* to 133, not the actual size.
>
>> 		println("makeCrash will set bit \(badIndex) in BitVector of size \(lengthInBits)")	//	why does this crash ?
>> 		CFBitVectorSetBitAtIndex( bitVector, badIndex, 1 )
>
> Why would you expect this to work? The documentation clearly states:
> 	 "The index must be in the range 0…N-1, where N is the count of the vector.”
>
>> 	}
>> }
>>
>> What am I doing wrong?
>
> You’re trying to set a bit at a bad index.

You are correct.
I - although reading the docs several times - failed to understand the difference between capacity and size.
Thanks for pointing this out.

Kind regards,

Gerriet.



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Why does Swift crash my CFBitVector ? (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Why does Swift crash my CFBitVector ? (From: "Clark S. Cox III" <email@hidden>)

  • Prev by Date: Re: Why does Swift crash my CFBitVector ?
  • Next by Date: Re: Swift crash in dispatch_apply
  • Previous by thread: Re: Why does Swift crash my CFBitVector ?
  • Next by thread: App icon is being mangled when built
  • Index(es):
    • Date
    • Thread