开发者

tap detecting garbage value

开发者 https://www.devze.com 2023-01-19 22:21 出处:网络
I\'m using Apple TapDetectingImageView class from Autoscroll example. Static analizer shows the following warning:

I'm using Apple TapDetectingImageView class from Autoscroll example.

Static analizer shows the following warning:

Classes/TapDetectingImageView.m:68:30:{68:17-68:29}: warning:

The left operand of '==' is a garbage value
         if (tapCounts[0] == 1 && tapCounts[1] == 1) {
             ~~~~~~~~~~~~ ^

for the attached code below. Garbage value occurs when a variable is read without having been initialized first. But it seems tapCounts is initialized already.

Can I ignore it if the app is running fine or should I modify anything?

    BOOL allTouchesEnded = ([touches count] == [[event touchesForView:self] count]);

// first check for plain single/double tap, which is only possible if we haven't seen multiple touches
if (!multipleTouches) {
    UITouch *touch = [touches anyObject];
    tapLocation = [touch locationInView:self];

    if ([touch tapCount] == 1) {
        [self performSelector:@selector(handleSingleTap) withObject:nil afterDelay:DOUBLE_TAP_DELAY];
    } else if([touch tapCount] == 2) {
        [self handleDoubleTap];
    }
}   

// check for 2-finger tap if we've seen multiple touches and haven't yet ruled out that possibility
else if (multipleTouches && twoFingerTapIsPossible) {

    // case 1: this is the end of both touches at once
    if ([touches count] == 2 && allTouchesEnded) {
        int i = 0;
        int tapCounts[2]; CGPoint tapLocations[2];
        for (UITouch *touch in touches) {
            tapCounts[i]    = [touch tapCount];
            tapLocations[i] = [touch locationInView:self];
            i++;
        }
        if (tapCounts[0] == 1 && tapCounts[1] == 1) { // it's a two-finger tap if they're both single taps
            tapLo开发者_JS百科cation = midpointBetweenPoints(tapLocations[0], tapLocations[1]);
            [self handleTwoFingerTap];
        }
    }


This occurs when a variable is created but NOT initialized to a value. In the code above you do this:

int tapCounts[2];
...

But then don't initialize the array contents to anything before attempting to evaluate it in the if statement a few lines down:

if( tapCounts[0] == 1 && tapCounts[1] == 1 ) {
   ....
}

The compiler is warning you that the contents of tapCounts[0] is not initialized and is garbage.


It's due to tapCounts array is initialized with garbage values for index 0 and 1.

Please change the line:

int tapCounts[2]; CGPoint tapLocations[2];

with

int tapCounts[2] = {0,0}; CGPoint tapLocations[2] = {0,0};

This will remove the initialize warning while analyzing build

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号