protect decrementActivityCount against integer underflow.
This commit is contained in:
parent
069615a20d
commit
e2751e6ffc
1 changed files with 5 additions and 1 deletions
|
|
@ -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];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue