> On Jan 19, 2016, at 10:11 AM, Aandi Inston <aa...@quite.com> wrote: > > Thank you. The problem turned out to be a foolish mistake in the caller, > but this has alerted me to the need for a systematic check of the > conversion between BOOL and C integers.
The only thing likely to cause problems is if values other than 0 or 1 get assigned to a bool or BOOL, specifically values > 255. For example if you assign 256 to a BOOL it may end up as 0. This can happen if you refactor something like if (count) doSomething(); into BOOL shouldDoSomething = (count); … if (shouldDoSomething) doSomething(); Depending on the value of `count`, this can cause an overflow in the BOOL variable and give it an incorrect false value. The fix is to change the assignment to `(count != 0)`. That being said, any Cocoa method that returns BOOL should be trustable to return only NO (0) or YES (1), so there shouldn’t be a need to do any extra checks on conversions. —Jens _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com