protect decrementActivityCount against integer underflow.

This commit is contained in:
Peter Steinberger 2012-04-05 17:49:08 -07:00
parent 069615a20d
commit e2751e6ffc

View file

@ -111,7 +111,11 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25;
- (void)decrementActivityCount { - (void)decrementActivityCount {
[self willChangeValueForKey:@"activityCount"]; [self willChangeValueForKey:@"activityCount"];
OSAtomicDecrement32((int32_t*)&_activityCount); bool success;
do {
int32_t orig = _activityCount;
success = OSAtomicCompareAndSwap32(orig, MIN(orig - 1, orig), &_activityCount);
} while(!success);
[self didChangeValueForKey:@"activityCount"]; [self didChangeValueForKey:@"activityCount"];
[self updateNetworkActivityIndicatorVisibilityDelayed]; [self updateNetworkActivityIndicatorVisibilityDelayed];
} }